当前位置: 编程技术>.net/c#/asp.net
c# 实现窗体拖到屏幕边缘自动隐藏
来源: 互联网 发布时间:2014-10-13
本文导语: 以下给出源代码: (注:hide为窗体名称) 代码如下:private void hide_Load(object sender, EventArgs e) { System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer(); StopRectTimer.Tick += new EventHandler(timer1_Tick); StopRectTimer.Interval = 100; StopRectTimer.Ena...
以下给出源代码: (注:hide为窗体名称)
private void hide_Load(object sender, EventArgs e)
{
System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
StopRectTimer.Tick += new EventHandler(timer1_Tick);
StopRectTimer.Interval = 100;
StopRectTimer.Enabled = true;
}
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;
}
}
}
internal AnchorStyles StopAanhor = AnchorStyles.None;
private void mStopAnhor()
{
if (this.Top
c#通过委托delegate与Dictionary实现action选择器代码举例
C#实现获取枚举中元素个数的方法
C#实现自定义双击事件
C#键盘输入回车键实现点击按钮效果的方法
C#实现获取一年中是第几个星期的方法
C#实现Datatable排序的方法
C#实现装箱与拆箱操作简单实例
解决C#中WebBrowser的DocumentCompleted事件不执行的实现方法
C#下实现创建和删除目录的实例代码
使用C#实现在屏幕上画图效果的代码实例
C#实现过滤html标签并保留a标签的方法
c#实现TextBox只允许输入数字
C# Winform 整个窗口拖动的实现代码
c# ListView实现双击Item事件的变通方法
C#实现随鼠标移动窗体实例
C#中的FileUpload 选择后的预览效果具体实现
C# 窗体隐藏及任务管理器中禁止关闭的实现代码
C#的锯齿数组以及C++实现代码
C#格式化文件大小的实现代码
C#怎样才能实现窗体最小化到托盘呢?
代码如下:
private void hide_Load(object sender, EventArgs e)
{
System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
StopRectTimer.Tick += new EventHandler(timer1_Tick);
StopRectTimer.Interval = 100;
StopRectTimer.Enabled = true;
}
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;
}
}
}
internal AnchorStyles StopAanhor = AnchorStyles.None;
private void mStopAnhor()
{
if (this.Top