测试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 - 测试基础 - 自动
自动化测试模型 一个自动化测试框架就是一个集成体系,在这一体系中包含测试功能的函数库.测试数据源.测试对象识别标准,以及种可重用的模块. 自动化测试框架在发展的过程中,不断有新的模型(概念)被提出,目 ...
随机推荐
- 英语hecatolite月长石hecatolite月光石
月长石英文名字为hecatolite即月光石.当白色的光照到宝石上因宝石内特殊的结构而产生干涉颜色,在宝石表面可见到白至淡蓝色的闪光,犹如朦胧月光.这是由于正长石出溶有钠长石,钠长石在正长石晶体内定向 ...
- EXCHANGE上冒充任意用户--Exchange Server权限提升漏洞(CVE-2018-8581)分析
0x00 前言 这是我们2018年Top 5趣案系列中的第三个案例.这些漏洞都有一些因素使它们从今年发布的大约1,400个报告中脱颖而出.今天我们将分析一个Exchange漏洞,它允许任何经过身份验证 ...
- Java集合学习(4):HashTable
一.概述 和HashMap一样,Hashtable也是一个散列表,它存储的内容是键值对. Hashtable在Java中的定义为: public class Hashtable<K,V> ...
- 初探PHP设计模式
设计模式不是一套具体的语言框架,是行之有效的编码规范,是一套被反复使用.多数人知晓的.经过分类的.代码设计经验的总结.使用设计模式的目的:为了代码可重用性.让代码更容易被他人理解.保证代码可靠性.合理 ...
- java读取Properties文件的方法
resource.properties的内容: com.tsinkai.ettp.name=imooc com.tsinkai.ettp.website=www.imooc.com com.tsink ...
- python正则表达式(7)--flag修饰符、match对象属性
正则表达式—修饰符 正则表达式可以包含一些标志修饰符来控制匹配模式,用在正则表达式处理函数中的flag参数中,为可选参数. (1) re.I 全写(re.IGNORECASE) 表示使匹配时,忽略大小 ...
- python应用-彩票随机码的输出
""" 双色球-6个红色球(1-33)和一个蓝色球(1-16) """ from random import randint def sel ...
- nuxt 中使用 koa-session
官方 github 网址:https://github.com/koajs/session 自己做的demo:https://github.com/cag2050/nuxt_session_demo ...
- hive中时间操作(一)
转:https://blog.csdn.net/u012474716/article/details/78925319/ hive中常用的时间为时间戳和日期格式之间的转换 常用的函数为: to_dat ...
- dump array
<?php //array_dump.php $a=array(); $a[]=1; $a[]=2; $a[]=3; $a[]=4; $a[]='a'; $a[]='b'; $a[]='c'; ...