[Problem]
I wrote a section of C # form code, which is not displayed at the desktop position I specified during running. I don't know why? The Code is as follows:
Public class MyForm: Form
{
MyForm ()
{
Text = "Why doesn' t this form go where I want it to go? ";
Export toplocation = new System. Drawing. Point (500,500 );
}
Static void Main ()
{
Run (new MyForm ());
}
}
The title bar in the form is displayed normally, but the specified toplocation does not seem to work.
[Answer]
DesktopLocation can be set as you like, but MS. NET Framework does not pay attention to your settings unless you set StartPosition as follows:
StartPosition = Form. StartPosition. Manual;
It's easy to figure out what this line of code is for. Form. StartPosition tells. NET Framework where to start displaying the Form. Possible values include CenterParent, CenterScreen, Manual, WindowsDefaultBounds, and WindowsDefaultLocation. StartPosition: WindowsDefaultLocation by default. CreateWindow is equivalent to CW_USEDEFAULT.
Some people will certainly ask: What is the difference between Location and other toplocation? The answer is: the Location is relative to the screen, and the top Location is relative to the desktop Workspace-that is, the screen area except the taskbar. In this case, you have to consider which of the nerves of a user is not right and fill the taskbar wide with the whole screen.
If this happens, you can set Form. Location = (0, 0) to hide some forms, and ignore toplocation = (0, 0) to reconsider everything. Using toplocation can also be used in multiple monitor systems. (If you have programmed a wall-mounted plasma screen, it will be clear ). In addition, if you want to find the toplocation setting in the attribute window of Visual Studio, which is hard to solve and cannot be found, it can only be set by encoding. Really awesome!