Winform窗口弹出位置控制

Winform窗口弹出位置控制

窗体的弹出位置可以由属性StartPosition来指定,默认值有:

Manural  自定义,由属性Location指定;

CenterScreen  屏幕中央;

WindowsDefaultBounds   系统默认位置(但大小为系统默认窗体大小)

WindowsDefaultLocation  系统默认位置(大小由属性Size指定)

CenterParent  父窗体中央

指定窗体显示位置的代码:

?
this .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

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

代码实现:

?
this .Location = new System.Drawing.Point(100,100);

实现窗体在屏幕右下角显示:

经常看到有的软件在屏幕右下角弹出消息窗,用下面的代码可以简单实现:

?
public Form1()
{
InitializeComponent();
//获取当前工作区宽度和高度(工作区不包含状态栏)
int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int ScreenHeight = Screen.PrimaryScreen.WorkingArea.Height;
//计算窗体显示的坐标值,可以根据需要微调几个像素
int x = ScreenWidth - this .Width - 5;
int y = ScreenHeight - this .Height - 5;
this .Location = new Point(x,y);
}

运行结果:

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值