C#窗体靠边隐藏代码
2010-12-02 13:58
375 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
/// <summary>
/// 窗体根据每秒一刷新。来隐藏窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <summary>
/// 来判断位置的隐藏
/// </summary>
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();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
/// <summary>
/// 窗体根据每秒一刷新。来隐藏窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
}
/// <summary>
/// 来判断位置的隐藏
/// </summary>
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();
}
}
}
相关文章推荐
- C#中让窗体自动靠边隐藏
- 整理的c#winform窗体热键隐藏代码及存在的问题
- C#窗体隐藏标题栏后,鼠标可拖动窗口的代码!
- [原创]C#一键隐藏QQ/MSN窗体原代码下载
- C#中让窗体自动靠边隐藏
- C# 在winform中隐藏或者去除c#的标题栏并实现窗体移动附代码
- C#中无边框窗体随意移动代码
- C#实现QQ窗体隐藏(第一版)
- C#实现系统托盘,C#窗体最小化时隐藏为任务栏图标的Window appllication
- 在winfrom下利用c#代码,实现kindEditor的JavaScript方法:editor.html(),实现上报窗体的自动提交。
- C# winform 窗体覆盖(遮住)系统任务栏 (代码收藏)
- c# 实现窗体拖到屏幕边缘自动隐藏
- C#程序怎么操作某个进程的窗体显示隐藏
- C# 窗体加载时隐藏的问题
- C#读写Access数据库、表格datagridview窗体显示代码实例
- C#让窗体在启动时直接隐藏
- c# 隐藏主窗体
- C#窗体支持多个文件拖放的代码实现
- C#实现系统托盘,C#窗体最小化时隐藏为任务栏图标