Form stays on lefttop corner

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hello,

My form with Borderstyle set to none and ControlBox and MaximizeBox and
MinimizeBox set to false stays on location 0;0 (topleft)
but I want the form centered to the screen, so I added in the formload event
:
Rectangle screen = Screen.PrimaryScreen.Bounds;

this.Location = new Point((screen.Width - this.Width) / 2,

(screen.Height - this.Height ) / 2);



no result ! the form stays on topleft location 0;0

Is the a solution for this problem ?



thanks

Peter.
 
It certainly works for WindowsCE devices but not for PocketPC due to the
fact that a window shows as fullscreen. To avoid this limitation you may
position window by yourself:

Load Event Handler
{
Rectangle screen = Screen.PrimaryScreen.Bounds;
this.Location = new Point((screen.Width - this.Width) / 2,
(screen.Height - this.Height ) / 2);

//
// below goes new code
//

this.Capture = true;
IntPtr hwnd = OpenNETCF.Win32.Win32Window.GetCapture();
this.Capture = false;

OpenNETCF.Win32.Win32Window.SetWindowPos(hwnd,
Win32Window.SetWindowPosZOrder.HWND_TOP, this.Location.X,
this.Location.Y, this.Width, this.Height, 0);
}

Hope this help,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Thanks Sergey,

the code you gave is working on a WinCe 4.2 device.

the code :is not working on my wince 4.2 device ! (for a borderless form)

your code and the OpenNet code did the trick.

Kind regards

Peter.
 
Back
Top