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);

  根据上边的方法,咱们就能够随便自定义窗口的弹出位置,很简单方法

相关文章
相关标签/搜索