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); //设置窗体打开后在显示器上的座标

 

文章部分引自:http://hi.baidu.com/kaixinpengpeng/blog/item/605d6f093100d9cc3bc763c0.html

发布了73 篇原创文章 · 获赞 5 · 访问量 33万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章