C#设置窗体最大化 最小化 顶端显示

来源:互联网 发布:java for循环 小数点 编辑:程序博客网 时间:2024/05/19 00:11

设置全屏:
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.TopMost = true;      //这个一定要设置,不然一般会出现Bug

取消全屏,正常化:

this.FormBorderStyle = FormBorderStyle.Sizable;

this.WindowState = FormWindowState.Normal;

 

最小化:

this.FormBorderStyle = FormBorderStyle.Sizable;

this.WindowState = FormWindowState.Minimized;

 

获取屏幕尺寸:

int ScreenHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;  //显示器高度

int ScreenWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;    //显示器宽度

设置窗体居中最顶端显示 

this.SetBounds((System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - this.Width) / 2, 0, this.Width, this.Height);

 

如再要使得某个控件全屏,如GlobeContril、MapControl,只需要将他们的Top、Left、Width、Height等属性

设置为屏幕大小即可。

原创粉丝点击