Scott Gross
Top achievements
Rank 1
Scott Gross
asked on 02 May 2007, 04:23 AM
What is the proper way to proportionally resize a form?
Currently I just have:
This correctly resizes the height when it's horizontally resized, but it flickers between the initial size and the "dragging" size.
Any idea on how to fix this?
I need this to work vertically as well. Ideally I'd like to have the ratio calculated from the initial size.
Hope someone can help.
Thank you
Currently I just have:
private void Form1_Resize(object sender, EventArgs e) |
{ |
this.Height = this.Width; |
} |
This correctly resizes the height when it's horizontally resized, but it flickers between the initial size and the "dragging" size.
Any idea on how to fix this?
I need this to work vertically as well. Ideally I'd like to have the ratio calculated from the initial size.
Hope someone can help.
Thank you
4 Answers, 1 is accepted
0
Hello,
You can try the following solution for resizing a form proportionally.
Place the following code in your form:
The actual resizing is executed in the FormResize method.
I hope this works for you.
All the best,
Ray
the telerik team
Instantly find answers to your questions at the new Telerik Support Center
You can try the following solution for resizing a form proportionally.
Place the following code in your form:
protected override void WndProc(ref Message m) |
{ |
const int WM_EXITSIZEMOVE = 0x232; |
const int WM_SYSCOMMAND = 0x112; |
switch (m.Msg) |
{ |
case WM_EXITSIZEMOVE: // Form is moved or resized |
base.WndProc(ref m); |
FormResized(); |
break; |
case WM_SYSCOMMAND: // System command (maximize, minimize, restore, etc.) |
base.WndProc(ref m); |
const int SC_MAXIMIZE = 0xF030; |
const int SC_MINIMIZE = 0xF020; |
const int SC_RESTORE = 0xF120; |
switch (m.WParam.ToInt32()) |
{ |
case SC_MAXIMIZE: // Form is maximized by control |
case SC_MAXIMIZE + 2: // Form is maximized by title bar |
FormResized(); |
break; |
case SC_MINIMIZE: // Form is minimized by control |
FormResized(); |
break; |
case SC_RESTORE: // Form is restored by control |
case SC_RESTORE + 2: // Form is restored by title bar |
FormResized(); |
break; |
default: |
break; |
} |
break; |
default: |
base.WndProc(ref m); |
break; |
} |
} |
private int lastWidth; |
private int lastHeight; |
void FormResized() |
{ |
if (this.Width != this.lastWidth) |
{ |
this.Height = this.Width; |
} |
else |
if (this.Height != this.lastHeight) |
{ |
this.Width = this.Height; |
} |
this.lastWidth = this.Width; |
this.lastHeight = this.Height; |
} |
The actual resizing is executed in the FormResize method.
I hope this works for you.
All the best,
Ray
the telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
MattLynch
Top achievements
Rank 1
answered on 02 May 2007, 08:19 AM
You can also try this:
this.SuspendLayout();
// perform any special resizing...
this.ResumeLayout();
0
Scott Gross
Top achievements
Rank 1
answered on 02 May 2007, 04:10 PM
this is close. I need it to resize dynamically while I'm dragging though. Is there a way to make it dynamic?
0
MattLynch
Top achievements
Rank 1
answered on 02 May 2007, 04:33 PM
Your requirements are specialized, so your code needs to be specialized too.
Try this: Take Telerik's sample, and modify the FormResized method.
Have you thought about what happens on a wide screen monitor? In a maximized state, your controls will not be proportional, because the screen size is not a square. To maintain the correct proportions, you would need to disable maximizing (2 cases - via the title bar + via the control box).
Have fun...
Try this: Take Telerik's sample, and modify the FormResized method.
void FormResized() |
{ |
this.SuspendLayout(); |
if (this.Width != this.lastWidth) |
{ |
this.Height = this.Width; |
} |
else |
if (this.Height != this.lastHeight) |
{ |
this.Width = this.Height; |
} |
this.lastWidth = this.Width; |
this.lastHeight = this.Height; |
this.ResumeLayout(); |
} |
Have you thought about what happens on a wide screen monitor? In a maximized state, your controls will not be proportional, because the screen size is not a square. To maintain the correct proportions, you would need to disable maximizing (2 cases - via the title bar + via the control box).
Have fun...