C # desktop positioning of forms

Source: Internet
Author: User
[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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.