Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I want to repositioning a controll when form resizes or maximised. What will be the code.

for example I've placed a commandbutton lower right corner of the form. If the form maximised or resized then the command button will in the same position.
Posted

this alwais positon button at 80% of form widht and 80 % of form Height :

C#
private void fMain_Resize(object sender, EventArgs e)
{
    button1.Location = new Point((int)((float)this.Location.X * 0.8), (int)((float)this.Location.Y * 0.8));
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Mar-11 20:57pm    
Technically, it will work (the code is much more complex that is should be, also, a violation of Microsoft naming conventions) but in practice, a disaster. How it takes into account button size?! What's the "word constant", 80%, why on Earth?!
Just "3" this time, sorry...
--SA
See my old Answer on how to solve the problem different screen resolutions: Zom Out malfunctions when Screen resolution changes[^]. A problem of different form sizes require exact same approach.

I also need to add: Use properties MinimumSize and MaximumSize: it's also a critical thing to UI layout robustness.

See also: GUI Apperance - C#.Net[^].

—SA
 
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