Form position when maximized.

  • Thread starter ITALstudio s.r.l.
  • 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.
 
I

ITALstudio s.r.l.

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.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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;
 
I

ITALstudio s.r.l.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top