user1794844
user1794844

Reputation: 47

Form height of panel

I am having questions about a program that I'm developing. Sorry if my post is not clearly legible, as a beginner programming perfectionist I try to explain everything clearly as possible.

I have a Windows Form called frmMain.vb with two separate panels, one is called sidebarPanel and the other one is called mainPanel:

https://i.sstatic.net/Zs2lt.png

At runtime, this is how the form looks like: I reduced the screen to let it fit in this topic, the actual size is 900, 600 through this code at frmMain_Load:

Me.Size = New Size(900, 600)

https://i.sstatic.net/gdA3z.png

Now I have created the following piece of code:

With sidebarPanel
    .Top = 0
    .Left = 0
    .Width = 200
    .Height = 300
End With

With mainPanel
    .Top = 0
    .Left = 200
    .Width = 200
    .Height = 300
End With

In case you're wondering how the sidebar is blue, that piece comes from a dll, that piece of the code I've left out to keep this question easy. If you look closely at the source code you can see that the sidebar has a width of 200 and the mainpanel start 200 width from the left.

With that out of the way. I want to know the answer, I've searched Stackoverflow, Google and some VB.NET forums about these questions but I seem to be a loner.

How can I make the sidebar a full 100% height to the form so if I resize, the sidebar will change height too. That same question goes for the mainpanel.

Thank you for reading and thank you for the hospitality and the answer.

Upvotes: 1

Views: 7025

Answers (2)

SSS
SSS

Reputation: 5393

You might find it easier to use a SplitContainer control.

For more complicated control layouts you can use a TableLayoutPanel to arrange your controls: set the TableLayoutPanel.Dock property to Fill, then set the .Anchor properties of each control inside the TableLayoutPanel. There is a little arrow in the top right of the TableLayoutPanel (during design time) that allows you to specify the heights and widths of the rows and columns.

Upvotes: 1

Steven Doggart
Steven Doggart

Reputation: 43743

You can manually do so in the form's Resize event, by setting the Height property of the panels to Me.ClientSize.Height, however, it's easier to just do it all at design time.

To do so, in the form designer, first position and resize the panels so that they are where you want them to be for the current form size, then set the Dock property appropriately on both. You want the side panel's Dock property to be set to Top, Left, and Bottom. You probably want the main panel's Dock property set to Top, Bottom, Left, and Right (all four sides). When the dock property is set properly, the controls will automatically resize themselves as the form is resized.

After you have set the Dock property, you can test it by resizing the form right in the designer.

Upvotes: 2

Related Questions