c winform 窗體起始位置 設定

2021-08-03 08:15:21 字數 1782 閱讀 2314

窗體起始位置為頂部中間,winform居中顯示:

int x = (system.windows.forms.systeminformation.workingarea.width - this.size.width) / 2;  

int y = (system.windows.forms.systeminformation.workingarea.height - this.size.height) / 2;

this.startposition = formstartposition.manual; //

窗體的位置由location屬性決定

this.location = (point)new size(x, y); //

窗體的起始位置為(x,y)

其他注意點:

system.windows.forms.systeminformation.workingarea.width //

螢幕寬度

system.windows.forms.systeminformation.workingarea.height //

螢幕高度(去系統工作列,當顯示有工作列的時候)

this.size.width //

自己窗體的寬度,

this.size.width //

自己窗體的高度

this.clientrectangle.width //

工作區域寬度

this.clientrectangle.height //

工作區域高度設定視窗初始位置

this.startposition = formstartposition.manual; //

窗體的位置由location屬性決定

this.startposition = formstartposition.centerparent; //

窗體在其父窗體中居中

this.startposition = formstartposition.centerscreen; //

窗體在當前顯示視窗中居中,尺寸在窗體大小中指定

this.startposition = formstartposition.windowsdefaultbounds; //

窗體定位在windows預設位置,邊界也由windows預設決定

this.startposition = formstartposition.windowsdefaultlocation; //

窗體定位在windows預設位置,尺寸在窗體大小中指定

通過指定窗體locaiton來,設定窗體位置

this.startposition = formstartposition.manual; //

窗體的位置由location屬性決定

this.location = (point)new size(0, 0); //

窗體的起始位置為0,0

建立窗體時, 設定寬度和高度

this.clientsize = new system.drawing.size(x1,y1); //

x1 為寬度,y1為高度

獲取螢幕大小(using system.drawing)

rectangle rect = screen.getworkingarea(this

);point p = new

point(rect.width,rect.height);

this.location = p;

c winform 窗體起始位置 設定

窗體起始位置為頂部中間,winform居中顯示 int x system.windows.forms.systeminformation.workingarea.width this.size.width 2 int y system.windows.forms.systeminformation....

C winform 設定窗體的啟動位置

只需要設定窗體的startposition屬性 registerform.startposition formstartposition.centerscreen formstartposition的全部列舉值 成員名稱 說明centerparent 窗體在其父窗體中居中。centerscreen ...

C winform 設定窗體的啟動位置

只需要設定窗體的startposition屬性 registerform.startposition formstartposition.centerscreen formstartposition的全部列舉值 成員名稱 說明centerparent 窗體在其父窗體中居中。centerscreen ...