C#实现窗口靠近屏幕边缘自动吸附
2014-05-15 10:34
1306 查看
C#中实现窗口靠近屏幕边缘,自动吸附。
只需创建Form窗口的MOVE事件响应方法即可。
代码如下:
private void Form1_Move(object sender, EventArgs e)
{
int screenRight = Screen.PrimaryScreen.Bounds.Right;//屏幕右边缘
int formRight = this.Left + this.Size.Width;//窗口右边缘=窗口左上角x+窗口宽度
if (Math.Abs(screenRight - formRight) <= 100)//往右靠
this.Location = new System.Drawing.Point(screenRight-this.Size.Width,this.Top);//当前窗口坐标赋值,实现吸附
if (Math.Abs(this.Left) <= 100)//往左靠
this.Location = new System.Drawing.Point(0, this.Top);
int screenBottom = Screen.PrimaryScreen.Bounds.Bottom;//屏幕下边缘
int formBottom = this.Top + this.Size.Height;//窗口下边缘
if (Math.Abs(screenBottom - formBottom) <= 60)//往下靠
this.Location = new System.Drawing.Point(this.Left, screenBottom-this.Size.Height);
if (Math.Abs(this.Top) <= 100)//往上靠
this.Location = new System.Drawing.Point(this.Left,0);
}
只需创建Form窗口的MOVE事件响应方法即可。
代码如下:
private void Form1_Move(object sender, EventArgs e)
{
int screenRight = Screen.PrimaryScreen.Bounds.Right;//屏幕右边缘
int formRight = this.Left + this.Size.Width;//窗口右边缘=窗口左上角x+窗口宽度
if (Math.Abs(screenRight - formRight) <= 100)//往右靠
this.Location = new System.Drawing.Point(screenRight-this.Size.Width,this.Top);//当前窗口坐标赋值,实现吸附
if (Math.Abs(this.Left) <= 100)//往左靠
this.Location = new System.Drawing.Point(0, this.Top);
int screenBottom = Screen.PrimaryScreen.Bounds.Bottom;//屏幕下边缘
int formBottom = this.Top + this.Size.Height;//窗口下边缘
if (Math.Abs(screenBottom - formBottom) <= 60)//往下靠
this.Location = new System.Drawing.Point(this.Left, screenBottom-this.Size.Height);
if (Math.Abs(this.Top) <= 100)//往上靠
this.Location = new System.Drawing.Point(this.Left,0);
}
相关文章推荐
- 实现悬浮窗口自动吸附到屏幕边缘
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- C#实现窗体靠近屏幕边界自动隐藏
- c# 实现窗体拖到屏幕边缘自动隐藏
- 窗口在屏幕边缘自动隐藏的实现(动态收缩与动态弹出)
- qt实现的窗口吸附屏幕边缘,动画隐藏显示的效果,类似于qq主窗口 吸附 隐藏的效果
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- C#实现窗体靠近屏幕边界自动隐藏
- c# 实现窗体拖到屏幕边缘自动隐藏
- C# WPF 仿QQ靠近屏幕上方自动缩起功能实现
- C# WPF 如何禁止窗口拖到屏幕边缘自动最大化
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- Windows 10怎么使用智能的靠近屏幕边缘自动排列窗口?
- C# 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- 窗口在屏幕边缘自动隐藏的实现(动态收缩与动态弹出)(转)
- Win7中窗口被拖到屏幕边缘时自动最大化的解决方法
- C#实现仿QQ窗口靠边自动隐藏
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能