in C# Winforms, say I have several controls (labels, buttons, TextBox, ListBox, etc), and when the window is Maximized, I want those controls to be automatically resize to fit in the maximized windows, such that the position and size of those controls are in proportion when the windows is maximized. How do I achieve that? When the windows is maximized, isn't it that those texts in labels, buttons, Textbox, ListBox will automatically be increased proportionally? But I do not see that, even I try with different settings fro Anchor and Dock properties
I read from internet (http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/6165908)
about Anchor and Dock properties, but I try those and does not seem to work according to what I want.
I would also want the same solution for C# WPF.
thanks so much.
Some good examples would be helpful.
Loading
Brijendra GautamPosted Mar 24, 2014, 3:52 AM
Normal and maximized both.
seema bhoirPosted Mar 23, 2014, 9:19 AM
If I implement this solution then I can see equal size in default output screen however once I maximize it, controls in panel are not visible as picture box gets enlarged. Any comments ?
Brijendra GautamPosted Mar 23, 2014, 7:58 AM
seema bhoirPosted Mar 23, 2014, 6:51 AM
One additional question, I have placed one panel and one picture box on a form. I have set panel anchor properties -> left, top, bottom and picture box anchor properties -> left,right,top,bottom. However, its not allocating equal area to panel and picture box on the form.
How do we allocate equal area to panel and picture box that will be dynamic based on changing screen size ?
Brijendra GautamPosted Mar 13, 2014, 10:57 PM
Like this select Left and Right both then this control will stretch in horizontal direction. If you select Top and bottom both then stretch in Vertical direction.
When you select all four i.e. Top,Left,Bottom,Right then it will get resized in proportion to the size of window.
The idea is this, when you select anchor then it will maintain its distance from the wall of form.
TAN WhoAMIPosted Mar 13, 2014, 10:31 PM
TAN WhoAMIPosted Mar 13, 2014, 10:31 PM
seema bhoirPosted Mar 13, 2014, 10:15 PM
hi did you find any solution to this problem.I am facing same one,as I can able to set position but,When I tried it on bigger screen like 1920*1080 ,size of those controls are not in proportion as per screen size
I want to change font of all controls as screen size get change
waiting for your help
thanks
TAN WhoAMIPosted May 14, 2013, 1:29 AM
What I am looking for is: when user change the Form size, those controls inside the Form, will change proportionally, with its size and position.
something like http://stackoverflow.com/questions/3139052/how-to-resize-the-size-of-a-control-automatically-when-the-size-of-the-form-chan
void Form1_SizeChanged(object sender, EventArgs e){
myControl.Size = new Size(w,h); // size of the control
myControl.Location = new Point(x,y); //coordinates from the upperleft corner of your control's container (the form in your case)
}
Riddhi ValechaPosted May 13, 2013, 11:54 PM
http://www.codeproject.com/Articles/139930/A-simple-trick-to-resize-a-control-at-runtime
TAN WhoAMIPosted May 13, 2013, 8:17 PM
(last 2 posts), but they are not working for me. Can you test out with some simple label?
TAN WhoAMIPosted May 13, 2013, 4:03 AM
Riddhi ValechaPosted May 13, 2013, 3:38 AM
I am giving the business logic.. Hope this helps-
------------------
float widthRatio = Screen.PrimaryScreen.Bounds.Width / 1280;
float heightRatio = Screen.PrimaryScreen.Bounds.Height / 800f;
SizeF scale = new SizeF(widthRatio, heightRatio);
this.Scale(scale);
foreach (Control control in this.Controls)
{
control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
}
--------------------
add this code at page load do for all control or add all control in containers
int x; Point pt = new Point();
x = Screen.PrimaryScreen.WorkingArea.Width - 1024;
x = x / 2;
pt.Y = groupBox1.Location.Y + 50;
pt.X = groupBox1.Location.X + x;
groupBox1.Location = pt;