My winform can't change the size. The wince device is 480*764. I debugged and got a new size:
But the size still unchanged. What happened?
Try putting your sizing code into the constructor not the Load
event. Don't think that FormBorderStyle
needs to be sizable (is this even supported in the .NET Compact Framework which I assume you are using?). Our forms have a style of FixedDialog
. If you need to centre the form you can use this helper function which you call immediately after setting the size:
public static void SetFormPosition(Form frmChild)
{
// Set the form position on the Windows CE panel
if (frmChild != null)
{
// Get the size of the screen (should be 480x768)
Rectangle rctScreen = Screen.PrimaryScreen.WorkingArea;
// Now calculate the position of the form
int nPosX = ((rctScreen.Width - frmChild.Width) / 2);
int nPosY = ((rctScreen.Height - frmChild.Height) / 2);
// Set the position
frmChild.Location = new Point(nPosX, nPosY);
}
}