首页 > Windows开发 > 详细

Winfrom 弹出窗体位置设定

时间:2019-05-24 11:16:49      阅读:306      评论:0      收藏:0      [点我收藏+]

Winfrom 窗体弹出位置设定,其实就是两种模式,第一种模式是通过Winform提供的属性来设定;第二种模式是自定义,可以相对于软件本身,也可以是相对于屏幕。

一、第一种模式

  使用Winform提供的属性来设定窗体弹出的位置

技术分享图片

 

举个例子
 

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属性而定

  

二、第二种模式

自定义窗体弹出的位置,若自定义窗体显示位置,则属性StartPosition选择Manural,然后指定属性Location的坐标值。

举个例子

 相对于屏幕:

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

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

 

Winfrom 弹出窗体位置设定

原文:https://www.cnblogs.com/qtiger/p/10916630.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!