Library tutorials & articles
Planning Form Layout in VB.NET
- Introduction
- Getting Started
- Building the form
- The problem
- The solution
The solution
This is where a little code comes into play. To ensure that the panels resize in the desired manner we have to do two things:
- We have to change the width of the green panel proportionally to the change in width of the form.
- The height of green and the blue panels should remain constant. Which means we have to change the height of the red panel by the same value as the height of the form changes.
To accomplish the above tasks, do the following.
Declare these form level variable.
Private Const GreenPanelHeight As Integer = 117
Private Const FormHgtMinusRedPanelHgt As Integer = 232 - 88 'formHgt - PanelHgt
Private PrevFormWidth As Integer = 430Put the following code in the form resize event.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Dim WidthRatio As Double = (Me.Size.Width / PrevFormWidth)
GreenPanel.Size = New System.Drawing.Size(GreenPanel.Size.Width * WidthRatio, GreenPanelHeight)
PrevFormWidth = Me.Size.Width
RedPanel.Size = New System.Drawing.Size(RedPanel.Size.Width, Me.Size.Height - FormHgtMinusRedPanelHgt)
End Sub
Now save your work and run the application. You see that the form is working just as desired.
Now you can set the BackColor property of the panels back to its default values. Also set the MinimumSize property of the form such that all controls are visible and usable.
Related articles
Related discussion
-
How to write a query set to excel using vb.net
by BarbaMariolino (1 replies)
-
Very Urgent regarding deleting the images from a folder
by rameshbandi (2 replies)
-
Block Accessing MSSQL 2000
by militia (0 replies)
-
.NET Developer in Ghana Required....
by sysview (0 replies)
-
Sending SMS to mobile using secure gateway from VB.net 2008 c#
by pratikasthana17 (0 replies)
Related podcasts
-
xpert to Expert: Inside Concurrent Basic (CB)
"Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...
I would use 4 panels in the following way:
1) one up (this is the extra panel that is not in your example). Set the Dock property to this one to Top and set the Height to whatever you want.
2) The Green panel will be inside the panel one. Set the Dock property to Left and set the Width to whatever you want
3) The Bleu panel also inside the panel one. Set the Dock property to Fill.
4) The fourth panel (the Red one) comes bottom (as child of the form) with Dock set to Fill. (this is also a difference to your example)
The rest of the things are the same.
What we have accomplished with the fourth panel ? The fact that the Height of the Blue/Green panels is fixed to the height of the Panel One, so no coding is necessary to keep the height fix.
The only problem left is that the Width of the Green panel is fixed and when the form is made wider it does not resize. So the only code necesary is to make the
Green panel wider according with the width of the form.
Best regards,
Dan
good work - and helpful!
Good one ! Keep it up ...
This is very very very nice
[6]keep it up[/6]
good work
This thread is for discussions of Planning Form Layout in VB.NET.