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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章