Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
SQL
I´ve got a form which maximum size is 300x300 pixels.
It can be resized and maximized. The problem:

If the user sets the window state to maximized, the forms location
is set to 0,0. Changing the Location property doesn´t help.

Is it possible to center it on the screen even if maximized?
And if yes, how is it done?

Plz Help Me It's Urgent.
Posted
Updated 4-Jan-13 0:50am
v2

XML
try this code.
<pre lang="Javascript">
function MyPopUpWin() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var win2 = window.open("filename.htm","Window2","status=no,height=200,width=150,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
win2.focus();
}</pre>
 
Share this answer
 
Hi
You can use from bellow code:

-------------------------------------------------------------------------------------
this.Location = new System.Drawing.Point(ScreenLen - WinLen, ScreenHeigh - WinHeigh);


And attention to bellow link:
http://stackoverflow.com/questions/5082610/get-and-set-screen-resolution[^]

http://stackoverflow.com/questions/10828179/how-to-get-the-resolution-of-screen-for-a-winrt-app[^]
 
Share this answer
 
hello friend
i think there is a property like default window layout. set this property to true.
i think it helps you.
 
Share this answer
 
Hi Try This

Load all the control in a container like pannel control and set the Anchor property to None

Hope this will help you
 
Share this answer
 
You have probably set the MaximumSize property of the form in the designer's property window. In addition the MaximizedBounds property should be set as this can specify both size and location.

MaximizedBounds is not shown in the designer property window, so you may as well move the code that sets both properties into the constructor.

e.g.
C#
private const int MaxFormWidth = 300, MaxFormHeight = 300;

internal Form1() {
  InitializeComponent();

  // Calculate maximized location
  Rectangle screen = Screen.PrimaryScreen.Bounds;
  Point maximizedLocation = new Point(
    (screen.Width - MaxFormWidth) / 2,
    (screen.Height - MaxFormHeight) / 2);

  this.MaximumSize = new Size(MaxFormWidth, MaxFormHeight);
  this.MaximizedBounds = new Rectangle(maximizedLocation, this.MaximumSize);
}


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