测试winform自动悬浮
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region MyRegion
/// <summary>
/// 定义了窗体隐藏、出现的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Tick()
{
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
{
//窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
switch (this.StopAanhor)
{
//窗体在顶部时时,隐藏在顶部,底部边界出现2像素
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
break;
//窗体在最左边时时,隐藏在左边,右边边界出现2像素
case AnchorStyles.Left:
this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
break;
//窗体在最右边时时,隐藏在右边,左边边界出现2像素
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
break;
}
}
}
internal AnchorStyles StopAanhor = AnchorStyles.None;
/// <summary>
/// 固定了窗体位置的类型
/// </summary>
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;
}
//窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
switch (this.StopAanhor)
{
//窗体在顶部时时,隐藏在顶部,底部边界出现2像素
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, (this.Height - 20) * (-1));
break;
//窗体在最左边时时,隐藏在左边,右边边界出现2像素
case AnchorStyles.Left:
this.Location = new Point((-1) * (this.Width - 20), this.Location.Y);
break;
//窗体在最右边时时,隐藏在右边,左边边界出现2像素
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, this.Location.Y);
break;
}
}
#endregion
#region MyRegion
//private void Form1_LocationChanged(object sender, EventArgs e)
//{
// this.mStopAnhor();
//}
//private void Form1_MouseMove(object sender, MouseEventArgs e)
//{
// if (this.ClientRectangle.Contains((new Point(e.X, e.Y))))
// {
// switch (this.StopAanhor)
// {
// case AnchorStyles.Top:
// //窗体在最上方隐藏时,鼠标接触自动出现
// this.Location = new Point(this.Location.X, 1);
// break;
// //窗体在最左方隐藏时,鼠标接触自动出现
// case AnchorStyles.Left:
// this.Location = new Point(1, this.Location.Y);
// break;
// //窗体在最右方隐藏时,鼠标接触自动出现
// case AnchorStyles.Right:
// this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
// break;
// }
// }
// else
// {
// //窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
// switch (this.StopAanhor)
// {
// //窗体在顶部时时,隐藏在顶部,底部边界出现2像素
// case AnchorStyles.Top:
// this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
// break;
// //窗体在最左边时时,隐藏在左边,右边边界出现2像素
// case AnchorStyles.Left:
// this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
// break;
// //窗体在最右边时时,隐藏在右边,左边边界出现2像素
// case AnchorStyles.Right:
// this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
// break;
// }
// }
//}
//private void Form1_MouseLeave(object sender, EventArgs e)
//{
//}
#endregion
public bool isLocationChanged { get; set; }
public bool isMouseLeave { get; set; }
#region MyRegion
private void Form1_LocationChanged(object sender, EventArgs e)
{
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;
}
isLocationChanged = true;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (this.ClientRectangle.Contains((new Point(e.X, e.Y))))
{
switch (this.StopAanhor)
{
case AnchorStyles.Top:
//窗体在最上方隐藏时,鼠标接触自动出现
this.Location = new Point(this.Location.X, 1);
break;
//窗体在最左方隐藏时,鼠标接触自动出现
case AnchorStyles.Left:
this.Location = new Point(1, this.Location.Y);
break;
//窗体在最右方隐藏时,鼠标接触自动出现
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
break;
}
}
else
{
//窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
switch (this.StopAanhor)
{
//窗体在顶部时时,隐藏在顶部,底部边界出现2像素
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
break;
//窗体在最左边时时,隐藏在左边,右边边界出现2像素
case AnchorStyles.Left:
this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
break;
//窗体在最右边时时,隐藏在右边,左边边界出现2像素
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
break;
}
}
}
private void Form1_MouseEnter(object sender, EventArgs e)
{
if (isLocationChanged && isMouseLeave)
{
if (this.ClientRectangle.Contains(PointToClient(MousePosition)))
{
switch (this.StopAanhor)
{
case AnchorStyles.Top:
//窗体在最上方隐藏时,鼠标接触自动出现
this.Location = new Point(this.Location.X, 1);
break;
//窗体在最左方隐藏时,鼠标接触自动出现
case AnchorStyles.Left:
this.Location = new Point(1, this.Location.Y);
break;
//窗体在最右方隐藏时,鼠标接触自动出现
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
break;
}
}
else
{
//窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
switch (this.StopAanhor)
{
//窗体在顶部时时,隐藏在顶部,底部边界出现2像素
case AnchorStyles.Top:
this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
break;
//窗体在最左边时时,隐藏在左边,右边边界出现2像素
case AnchorStyles.Left:
this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
break;
//窗体在最右边时时,隐藏在右边,左边边界出现2像素
case AnchorStyles.Right:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
break;
}
}
}
}
private void Form1_MouseLeave(object sender, EventArgs e)
{
if (!isLocationChanged|| isMouseLeave)
{
return;
}
isLocationChanged = false;
//if (this.ClientRectangle.Contains((new Point(e.X, e.Y))))
//{
switch (this.StopAanhor)
{
case AnchorStyles.Top:
//窗体在最上方隐藏时,鼠标接触自动出现
this.Location = new Point(this.Location.X, 1);
isMouseLeave = true; break;
//窗体在最左方隐藏时,鼠标接触自动出现
case AnchorStyles.Left:
this.Location = new Point(1, this.Location.Y);
isMouseLeave = true; break;
//窗体在最右方隐藏时,鼠标接触自动出现
case AnchorStyles.Right:
isMouseLeave = true; this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
break;
}
isMouseLeave = false;
//}
//else
//{
// //窗体隐藏时在靠近边界的一侧边会出现2像素原因:感应鼠标,同时2像素不会影响用户视线
// switch (this.StopAanhor)
// {
// //窗体在顶部时时,隐藏在顶部,底部边界出现2像素
// case AnchorStyles.Top:
// this.Location = new Point(this.Location.X, (this.Height - 2) * (-1));
// break;
// //窗体在最左边时时,隐藏在左边,右边边界出现2像素
// case AnchorStyles.Left:
// this.Location = new Point((-1) * (this.Width - 2), this.Location.Y);
// break;
// //窗体在最右边时时,隐藏在右边,左边边界出现2像素
// case AnchorStyles.Right:
// this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
// break;
// }
//}
}
#endregion
}
}
测试winform自动悬浮的更多相关文章
- [CareerCup] 12.6 Test an ATM 测试一个自动取款机
12.6 How would you test an ATM in a distributed banking system? 这道题问我们如何来测试一个自动取款机,我们首先要询问下列问题: - 谁来 ...
- c# winform 自动升级
winform自动升级程序示例源码下载 客户端思路: 1.新建一个配置文件Update.ini,用来存放软件的客户端版本: [update] version=2011-09-09 15:26 2.新 ...
- Jenkins+Ant/maven+Svn实现自动化部署,编译,运行,测试结果自动邮件通知
Jenkins+Ant+Svn实现自动化部署,编译,运行,测试结果自动邮件通知
- PCB 电测试--测试点数自动输出到流程指示中(读取TGZ Stephdr文件)
好不容易实现了 <PCB 无需解压,直接读取Genesis TGZ指定文件 > 正好这里有一项需求:PCB电测试--测试点数自动输出到流程指示中 一.自动输出测试点小结; 1.由于历史原因 ...
- spring boot测试类自动注入service或dao
使用Spring Boot进行单元测试时,发现使用@Autowired注解的类无法自动注入,当使用这个类的实例的时候,报出NullPointerException,即空指针异常. Spring Boo ...
- winform自动更新程序实现
一.问题背景 本地程序在实际项目使用过程中,因为可以操作电脑本地的一些信息,并且对于串口.OPC.并口等数据可以方便的进行收发,虽然现在软件行业看着动不动都是互联网啊啥的,大有Web服务就是高大上的感 ...
- WinForm 自动完成控件实例代码简析
在Web的应用方面有js的插件实现自动完成(或叫智能提示)功能,但在WinForm窗体应用方面就没那么好了. TextBox控件本身是提供了一个自动提示功能,只要用上这三个属性: AutoComple ...
- 一句话知识:如何解决winform自动缩放产生的布局问题.
转自http://www.cnblogs.com/KenBlove/articles/1281823.html有时候你会发现本来好好的WinForm程序在别的机器上显示的尺寸就不对了.这些问题主要发生 ...
- Testing - 测试基础 - 自动
自动化测试模型 一个自动化测试框架就是一个集成体系,在这一体系中包含测试功能的函数库.测试数据源.测试对象识别标准,以及种可重用的模块. 自动化测试框架在发展的过程中,不断有新的模型(概念)被提出,目 ...
随机推荐
- France Alternative forms Fraunce
Fraunce See also: france and Francë English France Alternative forms Fraunce In Fraunce, the inhabit ...
- GitHub Python项目推荐|瓦力Devops开源项目代码部署平台持续部署
GitHub Python项目推荐|walle - 瓦力 Devops开源项目代码部署平台 项目热度 标星(star):8418 (很不错的实用项目,大神作品,建议关注) 标星趋势 关注(watch) ...
- springmvc核心流程
用户请求DispathcerServlet(前端控制器). (前端控制器)DispatcherServlet接受到请求,将根据请求信息交给处理器映射器(HandlerMapping). 处理器映射器( ...
- Docker07-数据管理
目录 将数据保存在容器外部 挂载参数 -v 案例:运行mysql容器,将mysql的数据放在主机/data/mysql-data中. 将数据保存在容器外部 容器在运行项目时会产生数据,比如运行的mys ...
- 大数据:Hadoop(HDFS 读写数据流程及优缺点)
一.HDFS 写数据流程 写的过程: CLIENT(客户端):用来发起读写请求,并拆分文件成多个 Block: NAMENODE:全局的协调和把控所有的请求,提供 Block 存放在 DataNode ...
- Django之 RESTful规范
RESTful 规范 一.什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为"表征 ...
- Linux之ubuntu下载
(转载) ubuntu 16.04国内下载地址: 中科大源 http://mirrors.ustc.edu.cn/ubuntu-releases/16.04/ 阿里云开源镜像站 http://mirr ...
- SAMBA 服务配置
Samba文件共享服务 Linux系统中一种文件共享程序 在Windows网络环境中,主机之间进行文件和打印机共享是通过微软公司自己的SMB/CIFS网络协议实现的.SMB(Server Messag ...
- VS创建C工程
打开VS编辑器: 填写项目名称,控制项目位置,创建: 在源文件中添加新项: 填写文件名称,修改后缀: 编写一个简单的hello word编译看看windows环境支持如何:
- P5021 赛道修建[贪心+二分]
题目描述 C 城将要举办一系列的赛车比赛.在比赛前,需要在城内修建 mm 条赛道. C 城一共有 nn 个路口,这些路口编号为 1,2,-,n1,2,-,n,有 n-1n−1 条适合于修建赛道的双向通 ...