Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:06:01+00:00 2026-06-08T01:06:01+00:00

I have created a windows forms app that is very complex. What I am

  • 0

I have created a windows forms app that is very complex. What I am trying to do now is if different buttons are clicked to disable some panels but shift all the other panels underneath of it up so it looks in order. I am having such a hard time with this. I wanted to develop a function that passes in a Panel that is getting disabled and a list of all other panels underneath of it and using recursion rearrange all the panels. This function works but it does not take in consideration if one panel has a height bigger than the other it leaves extra spaces between the two panels. Any help would be much appreciated.

Public Sub whatever(ByVal panel As Panel, ByVal list As List(Of Panel))
    Dim temppanel As Panel = New Panel()
    For Each item As Panel In list
        temppanel.Location = New Point(temppanel.Location.X, item.Location.Y)
        item.Location = New Point(item.Location.X, panel.Location.Y)
        list.Remove(item)
        whatever(temppanel, list)
        If list.Count = 0 Then
            Exit For
        End If
    Next
End Sub

Image

http://imageshack.us/photo/my-images/268/panelsz.png/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:06:02+00:00Added an answer on June 8, 2026 at 1:06 am

    A FlowLayoutPanel probably is more appropriate for this, but here is a general method to do what I think you are looking for:

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
                              Handles Button1.Click
      ToggelPanel(Panel2)
    End Sub
    
    Private Sub ToggelPanel(ByVal whichPanel As Panel)
      Dim startPoint As New Point(10, 10)
      whichPanel.Visible = Not whichPanel.Visible
    
      For Each pnl As Panel In Me.Controls.OfType(Of Panel)(). _
                               Where(Function(x) x.Visible). _
                               OrderBy(Function(x) x.TabIndex)
        pnl.Location = startPoint
        startPoint.Y += pnl.Height + 4
      Next
    End Sub
    

    Replace Me with the parent container if these panels are not in Me.


    If using .net 2.0 where LINQ is not available, the function would look something like this:

    Private Shared Function CompareTabIndex(ByVal p1 As Panel, ByVal p2 As Panel) _
                                            As Integer
      Return p1.TabIndex.CompareTo(p2.TabIndex)
    End Function
    
    Private Sub ToggelPanel(ByVal whichPanel As Panel)
      Dim startPoint As New Point(10, 10)
      whichPanel.Visible = Not whichPanel.Visible
    
      Dim panels As New List(Of Panel)
      For i As Integer = 0 To Me.Controls.Count - 1
        If TypeOf Me.Controls(i) Is Panel Then
          If Me.Controls(i).Visible Then
            panels.Add(Me.Controls(i))
          End If
        End If
      Next
    
      panels.Sort(New Comparison(Of Panel)(AddressOf CompareTabIndex))
    
      For Each pnl As Panel In panels
        pnl.Location = startPoint
        startPoint.Y += pnl.Height + pnl.Margin.Bottom
      Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a C# DLL that has some forms in it. ( I
I created a Windows Forms app that generates reports and it works great. It
I have an MVC3 Intranet app that uses Windows authentication. I'm now using a
I have created a program with Windows Forms in C# and the architecture is
I have a form created in Windows Forms which is draggable wherever I click.
I have created two forms in my Windows Application. One Form acts as a
I have a C# Windows Forms application, whose prototype was created on SQL Server
I have a requirement to create a simple windows forms application that allows an
I have created a windows form application: A presentation library with several windows forms
I have a couple of powershell command that are very simple. disable-mailbox dadelgad -confirm:$false

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.