Reposition Controls on Form_Load

HardCode

Freshman
Joined
Apr 2, 2004
Messages
49
I have a Panel docked to the bottom of a form, with the some buttons on the right hand side of the Panel. On Form_Resize, I programmatically set the position of the buttons so that its position on the right is consistent, regardless of the form size.
Visual Basic:
btnClose.Left = pnlButtons.Width - btnClose.Width - 10
btnRefresh.Left = pnlButtons.Width - btnRefresh.Width - btnClose.Width - 20
btnUpdate.Left = pnlButtons.Width - btnUpdate.Width - btnRefresh.Width - btnClose.Width - 30
Now, in the Form_Load event I set the form to FormWindowState.Maximized, and the Form_Resize event is raised. However, at this time, the form is still the size as it is in the designer. Even explicitly calling Form_Resize again after setting it Maximized leaves me with the dimensions of the form in the designer (the form hasn't actually maximized until the Load event has completed).

Because of this, the buttons are in the wrong place on the form. They are not repositioned after the form loads. I can't seem to find an event that fires automatically after Form_Load, and after the form is actually maximized and the new size is accessible.

Or, is there a way in the designer to tell the controls to "stay where they are" in relation to the Panel, regardless of the Form and Panel resizing?
 
I swear I posted the same answer yesterday. I must have closed the window too fast or something...

I had used VB7 for quite a while before I discovered the anchor property, and since then I don't think I've written a single line of form resize code. You can use anchor to center something, anchor it to a single edge, or anchor it to two edges to make it stretch with its container. Very handy.
 
Back
Top