Form position when maximized.

  • Thread starter Thread starter ITALstudio s.r.l.
  • Start date Start date
I

ITALstudio s.r.l.

Hi,

I´ve got a form which maximum size is 400x500 pixels.This form can be
resized and maximized, because I don't want Disable Maximize button and set
FormBorderStyle = Sizable.At run-time if the user sets the window state to
maximized, the forms locationis set to 0,0. It's possible to center the form
on the screen even if maximized? Thanks in advance.
 
Hi AlexS,



Yes, I had already tried to do an test to insert the code into Resize event
of the form,

and verified that it worked but the result it has been that one of having
flickers to location the form.



Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

If Me.WindowState = FormWindowState.Maximized Then

Me.WindowState = FormWindowState.Normal

Me.CenterToScreen()

End If

End Sub



Thanks.
 
Hi,

Add this code in the form's constructor or Load event handler

Rectangle rect = Screen.FromControl(this).Bounds;
Rectangle newMaxBounds = new Rectangle((rect.Width - 400)/2,
(rect.Height - 400)/2, 400, 500);
this.MaximizedBounds = newMaxBounds;
 
Hi Stoitcho Goutsev,
Thank you very much for your help!
It works fine.


Stoitcho Goutsev (100) said:
Hi,

Add this code in the form's constructor or Load event handler

Rectangle rect = Screen.FromControl(this).Bounds;
Rectangle newMaxBounds = new Rectangle((rect.Width - 400)/2,
(rect.Height - 400)/2, 400, 500);
this.MaximizedBounds = newMaxBounds;


--
HTH
Stoitcho Goutsev (100) [C# MVP]


ITALstudio s.r.l. said:
Hi,

I´ve got a form which maximum size is 400x500 pixels.This form can be
resized and maximized, because I don't want Disable Maximize button and set
FormBorderStyle = Sizable.At run-time if the user sets the window state to
maximized, the forms locationis set to 0,0. It's possible to center the form
on the screen even if maximized? Thanks in advance.
 
Back
Top