Click here to Skip to main content
15,886,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i am currently calculating the parameter i need to build my GUI ChildControl is the child of "this" control.

C#
//while moving my ChildControl by mouse i am calculating this parameter   
ChildControl.SuperPosition = (float)(ChildControl.Top / (this.ClientSize.Height / 100.0));

protected override void OnSizeChanged (EventArgs eventargs)
{
     ChildControl.Top = (int)(ChildControl.SuperPosition * (this.ClientSize.Height / 100.0));

    base.OnSizeChanged (eventargs);
}


While Form state is Normal everything works fine. And the ChildControl.Top result is expected. But when i hit Maximize button. The ChildControl.Top changes to some unexpected way. Can anybody help with that?

When i am hitting Maximize box the child controls changes it`s Y position. It looks like Form changes it`s size but the "ClientSize" dose not change. And it is calculating position then changes the value of the size. Very strange. The same result is with the
C#
OnResize 
event and with
C#
OnClientSizeChanged
event.
Posted
Updated 11-Dec-14 14:59pm
v3

Most likely, you can get the best result from the form layout redesign. Generally, if layout is based on OnSizeChanged, this is a bad thing. One very usual problem with forms is that they overlap, but it becomes noticeable only at certain sizes. It's much better to achieve fluid/flexible layout by using more panels on different levels of parent-child relationship tree, with appropriate combination of Dock and Padding properties. First of all, you need to make sure that none of your controls gets DockStyle.None, to avoid the situation I described above. (There are some exclusions, for example, if your intention is to completely hide several panels under one to be shown, one at a time.)

Please see my past answers:
Zom Out malfunctions when Screen resolution changes[^],
how to dock button so that it can adjust with the form[^] (a rudimentary code sample here).

—SA
 
Share this answer
 
1. What type of Control is ChildControl ?

2. Why are you using the overloaded Resize ?

3. Put a break-point in your code to verify that the overloaded Resize Event Handler is actually called when you maximize the Form, restore it to "normal," minimize it, etc.

4. Put a break-point in your code before you calculate the value of ChildControl.Top: examine the values of SuperPosition, ClientSize.Height: then single-step (F11), and examine the values after you calculate. The answer will lie in how those values are not what you expect.

Make sure the ChildControl has Anchor and Dock properties set to: ChildControl.Anchor = AnchorStyles.None; ChildControl.Dock = DockStyle.None;

Try using the Form.Resize Event (not overloaded), as an alternative.

Consider if you may need to use the Form ResizeBegin and ResizeEnd Events to do what you need to, perhaps updating some "state variables" in the ResizeBegin code that are used in calculations performed in the ResizeEnd code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900