仿QQ 窗体拖到 windows窗体边上时,C#WinForm 自动隐藏

转载 2011年01月22日 09:48:00

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            System.Windows.Forms.Timer StopRectTimer = new System.Windows.Forms.Timer();
            StopRectTimer.Tick += new EventHandler(timer1_Tick);
            StopRectTimer.Interval = 50;
            StopRectTimer.Enabled = true;
            this.TopMost = true;
            StopRectTimer.Start();
        }

        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;
                    case AnchorStyles.Bottom:
                        this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height);
                        break;
                }
            }
            else
            {
                switch (this.StopAanhor)
                {
                    case AnchorStyles.Top:
                        this.Location = new Point(this.Location.X, (this.Height - 8) * (-1));
                        break;
                    case AnchorStyles.Left:
                        this.Location = new Point((-1) * (this.Width - 8), this.Location.Y);
                        break;
                    case AnchorStyles.Right:
                        this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, this.Location.Y);
                        break;
                    case AnchorStyles.Bottom:
                        this.Location = new Point(this.Location.X, (Screen.PrimaryScreen.Bounds.Height - 8));
                        break;
                }
            }

        }

        internal AnchorStyles StopAanhor = AnchorStyles.None;
        private void mStopAnhor()
        {
            if (this.Top <= 0 && this.Left <= 0)
            {
                StopAanhor = AnchorStyles.None;
            }
            else 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 if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height)
            {
                StopAanhor = AnchorStyles.Bottom;
            }
            else
            {
                StopAanhor = AnchorStyles.None;
            }
        }

        private void hide_LocationChanged(object sender, EventArgs e)
        {
            this.mStopAnhor();
        }

}

在WinForm中添加Load事件给Form1_Load,添加LocationChanged事件给hide_LocationChanged。

原理:主要是用Timer控件,在实时判断当前窗口的位置,如果在windows窗口的边上时,

         修改窗口的位置。当窗口隐藏后,实时判断鼠标的位置,如果在窗口附件,窗口显示。

相关文章推荐

C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm

C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm。代码:     public partial class Form1 : Form { ...

仿QQ窗体自动隐藏.pas

Qt实现窗体在显示屏旁边自动隐藏(类似QQ)

Qt实现窗体在显示屏旁边自动隐藏(类似QQ)看群里有人问这个东西,本人先来无事编以自己的想法实现了下: 其实实现的点子很简单:void AutoHideWidget::leaveEvent(QEve...

Java实现窗体隐藏,功能类似于QQ窗口自动隐藏

自己写java程序从开始接触到现在有近两年的时间了,一直还没有怎么接触到j2ee方面的知识,比如说那些常用的框架(struts、spring、hibernate),自己都还没接触过。最近做项目又做到与...

winform自动隐藏窗体

窗体的靠边自动隐藏

  • 2016-09-01 17:24
  • 246KB
  • 下载

winform实现任务栏隐藏、通知栏图标及右键、类似QQ隐藏窗体等功能

1。第一个功能是任务栏隐藏。winform下有个属性showintaskbar。直接改为false即可。 2。第二个功能是添加通知栏图标。有个控件为notifyicon,直接拉过来,添加图标即可。 3...

C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变

参考文章: 1 http://www.crifan.com/csharp_control_size_auto_changed_with_winform_size_changed/ 2 http://0...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)