问一个C#中窗体的问题~

来源:百度知道 编辑:UC知道 时间:2024/07/09 03:47:10
在做windows应用程序的时候,设置窗体时想要让窗体出现位置在屏幕中央,窗体大小固定,不能调整...这需要修改哪个属性啊?

startposition = centerscreen 出现再屏幕中间
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 固定大小

在窗体的构造函数中添加如下代码:

//posWidth 和PosHeight 为屏幕的宽和高,根据实际情况赋值
int posWidth = 800;
int PosHeight = 600;
int LocationX = (posWidth - this.Size.Width) / 2;
int LocationY = (PosHeight - this.Size.Height) / 2;
this.Location = new Point(LocationX,LocationY);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

startposition = centerscreen
style = fixeddialog

设置绝对位置