HardCode Posted June 14, 2006 Posted June 14, 2006 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? Quote
HJB417 Posted June 15, 2006 Posted June 15, 2006 Have you tried using the Anchor property? http://www.c-sharpcorner.com/winforms/AnchDocInWinFormsGAG.asp Quote
Leaders snarfblam Posted June 15, 2006 Leaders Posted June 15, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.