Panel and Control resizing

  • Thread starter Thread starter Bryan
  • Start date Start date
B

Bryan

I have a form that contains three panels, separated by
vertical splitters. Each panel has two child panels,
separated by horizontal splitters. Everything is
docked/anchored to fill the entire form container.

So, we have a 3 x 3 grid of resizable panels.

My goal is to save the size/position of each
panel/splitter to a class, so we can reset the controls to
the same size/position that the user left them in.

Here is my class (prop set/get & constructors omitted for
clarity):
Private Class ConsoleLayout
Private mControl As Control
Private mLocation As Point
Private mSize As Size
Private mAnchor As AnchorStyles
Private mDock As DockStyle
End Class

When the form closes, the following code would save the
positions to an array list of these classes:

Private myForms As New ArrayList
Private Sub Save(ByVal sender As System.Object, ByVal
e As System.EventArgs)
myForms.Clear()
Dim theControl As Control
For Each theControl In Me.Controls
myForms.Add(New ConsoleLayout(theControl,
theControl.Location, theControl.Size, theControl.Anchor,
theControl.Dock))
Next
End Sub


And here is the function that should "restore" the
size/position:
Private Sub Save()
Me.SuspendLayout()

Dim myLayout As ConsoleLayout
For Each myLayout In myForms
myLayout.Control.Location = myLayout.Location
myLayout.Control.Size = myLayout.Size
myLayout.Control.Anchor = myLayout.Anchor
myLayout.Control.Dock = myLayout.Dock
Next

Me.ResumeLayout()
End Sub



*** All the left/right positions are proper, however the
top/height positions/sizes don't seem to take
their "saved" settings.

I've inspected the values, and the class properly gets
the "new" values, but the control doesn't "take" the
Top/Height values I send to them.

I've experimented with limiting the Get/Set of just
panels, panels & splitters, etc but that didn't matter.

I also did Suspend Layout for just the panel controls, as
the Windows Form Generator code seems to do when the form
is originally loaded; that too had no affect.

Any ideas?
Regards,
Bryan
 
Just for clarification's sake:

The second function isn't named Save, but "restore" or
something else that doesn't conflict with the Save
function.

Also, the class stores a reference to the control, not an
instance of the control itself.

Thanks,
Bryan
 
I'm now performing research on the issue. I will update you as soon as
possible.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
If there is no "dock", I think there should no problem. When "dock" is
involved, the situation will become complex. When you add a docked control
to a form, it will affect the other controls on the same form. The order of
adding the controls will affect the layout. You should add the docked
controls one by one with the right order, otherwise, it will not work.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
What would be the proper order.... set the size of "inside" controls first,
or "outside" conainers?

Regards,
Bryan
 
You can refer to the code generated by the system after you designed your
form. The generated code is in the correct order.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
If you need more help, please feel free to let us know.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top