WinForm窗体屏幕边缘停靠(窗体靠边吸附代码)
来源:互联网 发布:人工神经网络算法 开源 编辑:程序博客网 时间:2024/05/10 03:20
1、方法一
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms; namespace WZDH{ public partial class Form1 : Form { internal AnchorStyles StopAanhor = AnchorStyles.None; public Form1() { InitializeComponent(); } /// <summary> /// 初始化窗体信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { //设置窗体左边距离主显示器位置 this.Width = 200; this.Left = Screen.PrimaryScreen.Bounds.Width - this.Width; //设置窗体顶边距离主显示器位置 this.Top = 0; //设置窗体宽度为主显示器宽度(不包括任务栏) this.Height = Screen.PrimaryScreen.WorkingArea.Height; } /// <summary> /// 淡入加载窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { this.Opacity += 0.1; if (this.Opacity >= 1) this.timer1.Enabled = false; } /// <summary> /// 退出程序菜单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmiExit_Click(object sender, EventArgs e) { Application.Exit(); } /// <summary> /// 当窗体的位置改变时发生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_LocationChanged(object sender, EventArgs e) { mStopAnhor(); } private void timer2_Tick(object sender, EventArgs e) { //如果鼠标在窗体上,则根据停靠位置显示整个窗体 if (this.Bounds.Contains(Cursor.Position)) { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, 0); break; case AnchorStyles.Bottom: this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height); break; case AnchorStyles.Left: this.Location = new Point(0, this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y); break; } } else //如果鼠标离开窗体,则根据停靠位置隐藏窗体,但须留出部分窗体边缘以便鼠标选中窗体 { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, (this.Height - 3) * (-1)); break; case AnchorStyles.Bottom: this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - 5); break; case AnchorStyles.Left: this.Location = new Point((-1) * (this.Width - 3), this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y); break; } } } private void mStopAnhor() { if (this.Top <= 0) { StopAanhor = AnchorStyles.Top; } else if (this.Left <= 0) { StopAanhor = AnchorStyles.Left; } else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width) { StopAanhor = AnchorStyles.Right; } else { StopAanhor = AnchorStyles.None; } } }}
1、方法二
#region //仿QQ窗体靠边吸附功能 private void Form1_Load(object sender, EventArgs e) { Timer StopRectTimer = new Timer(); StopRectTimer.Tick += new EventHandler(timer1_Tick); StopRectTimer.Interval = 100; StopRectTimer.Enabled = true; } internal AnchorStyles StopAanhor = AnchorStyles.None; private void timer1_Tick(object sender, EventArgs e) { if (this.Bounds.Contains(Cursor.Position)) { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, 0); break; case AnchorStyles.Left: this.Location = new Point(0, this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y); break; } } else { switch (this.StopAanhor) { case AnchorStyles.Top: this.Location = new Point(this.Location.X, (this.Height - 2) * (-1)); break; case AnchorStyles.Left: this.Location = new Point((-1) * (this.Width - 2), this.Location.Y); break; case AnchorStyles.Right: this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y); break; } } } private void mStopAnthor() { if (this.Top <= 0) { StopAanhor = AnchorStyles.Top; } else if (this.Left <= 0) { StopAanhor = AnchorStyles.Left; } else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width) { StopAanhor = AnchorStyles.Right; } else { StopAanhor = AnchorStyles.None; } } private void Form1_LocationChanged(object sender, EventArgs e) { this.mStopAnthor(); } #endregion
- WinForm窗体屏幕边缘停靠(窗体靠边吸附代码)
- Winform窗体实现类似停靠在屏幕边缘时自动隐藏的功能 .doc
- WinForm,窗体靠近屏幕边缘自动隐藏
- 像QQ一样当窗体在屏幕边缘时停靠(转载)
- WinForm:DockPanel实现窗体的停靠
- 窗体停靠
- 实现吸附窗体功能
- 停靠的窗体
- Delphi的窗体停靠
- C# 窗体可停靠
- WinForm之登录窗体代码
- winform 窗体重新加载代码
- C# 实现类似QQ的窗体在桌面边缘停靠和隐藏
- Flex: AIR程序靠屏幕边缘收起 屏幕边缘吸附
- 类似QQ窗体靠边隐藏原理
- c# 实现窗体拖到屏幕边缘自动隐藏
- c# 实现窗体拖到屏幕边缘自动隐藏
- 窗体靠近屏幕边缘自动隐藏*学习(类似于QQ)
- Web前端 ie6似乎不支持float:left 解决办法
- 一著名软件公司的java笔试算法题的答案
- Windows中提升程序运行权限
- C#Excel导入导出
- VC6.0 应用MSCOM控件
- WinForm窗体屏幕边缘停靠(窗体靠边吸附代码)
- 图片验证码
- 博客开通了很高兴
- SQL查询入门(中篇)
- ARM SoC体系结构
- Android开发适配器系列:Spinner使用自定义适配器
- 64位机器上的控件注册
- Android项目实战
- Android 动态获取图片