Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

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?

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...