c# 窗体位置任意调

发现窗体的位置只能通过StartPosition属性设置,而这个属性只提供了5种位置选项,很不够!

今天在网上找到了一个解决的方法,如下:

int x= System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width/2;
int y=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height /2;
this.SetDesktopLocation(x,y);

注释:
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width;   //当前显示器的宽度
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height; //当前显示器的高度
this.SetDesktopLocation(x,y); //设置窗体打开后在显示器上的坐标

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hejialin666/archive/2010/01/28/5266372.aspx

作者:观海看云个人开发历程知识库 - 博客园
出处:http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/zhangtao/p/1691893.html