Winfrom 彈出窗體位置設定

Winfrom 窗體彈出位置設定,其實就是兩種模式,第一種模式是經過Winform提供的屬性來設定;第二種模式是自定義,能夠相對於軟件自己,也能夠是相對於屏幕。this

1、第一種模式spa

  使用Winform提供的屬性來設定窗體彈出的位置orm

 

舉個例子
 blog

Form form1=new Form();
form1.StartPosition = FormStartPosition.CenterScreen;//窗體位置在屏幕中間
form1.StartPosition = FormStartPosition.CenterParent;//窗體在其父窗口中間
form1.StartPosition =FormStartPosition.WindowsDefaultBounds;//窗體位置由Windows默認位置決定,窗體大小也是Windows默認大小
form1.StartPosition =FormStartPosition.WindowsDefaultLocation//窗體位置是Windows默認,大小在窗體大小中肯定
form1.StartPosition = FormStartPosition.Manual;//窗體根據Location屬性而定

  

2、第二種模式it

自定義窗體彈出的位置,若自定義窗體顯示位置,則屬性StartPosition選擇Manural,而後指定屬性Location的座標值。io

舉個例子form

 相對於屏幕:class

int ScreenWidth =SystemInformation.VirtualScreen.Width;//獲取屏幕寬度
int ScreenHeight = SystemInformation.VirtualScreen.Height;//獲取屏幕高度
//計算窗體顯示的座標值,能夠根據須要微調幾個像素
int x = ScreenWidth - this.Width - 5;
int y = ScreenHeight - this.Height - 5;
form1.Location = new Point(x,y);

 相對於軟件自己軟件

好比說MainForm是主窗體,咱們要在主窗體的左邊彈出一個提示窗體form1

int x=MainForm.Location.X-form1.Width;//form1的X座標
int y=MainForm.Location.Y-form1.Height;//form1的Y座標
form1.Location = new Point(x,y);

  根據上邊的方法,咱們就能夠隨便自定義窗口的彈出位置,很簡單方法

相關文章
相關標籤/搜索