Click here to Skip to main content
11,430,908 members (68,946 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 4-Jan-13 1:25am
Edited 4-Jan-13 1:50am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hello friend
i think there is a property like default window layout. set this property to true.
i think it helps you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100