想实现鼠标离开,窗体自动隐藏,移入又显示,首先是要判断窗体边界有没超过屏幕的边界线,反正像Q那样的,主要是通过鼠标的事件来实现,这个问题怎么写呢,

解决方案 »

  1.   


    以屏幕左边为例:using System;
    using System.Windows.Forms;
    using System.Threading;
    using System.Runtime.InteropServices;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent(); 
            }        [DllImport("user32.dll")]
            static extern bool GetCursorPos(out System.Drawing.Point lpPoint);        private void timer1_Tick(object sender, EventArgs e)
            {
                if (this.Visible)
                {
                    if (this.Left <= 0)
                    {
                        this.Hide();
                    }
                }
                else
                {
                    System.Drawing.Point point = new System.Drawing.Point();
                    GetCursorPos(out point);
                    if (point.X <= 5)
                    {
                        this.Visible = true;
                        this.Left = 1;
                    }
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {
                this.timer1.Interval = 100;
                this.timer1.Enabled = true;
            }
        }
    }
      

  2.   

    你应该还没看懂把,为什么不可以,先做判断,判断窗体边缘是否超过屏幕边界,写在鼠标MouseUp事件里面,还要有鼠标的其他事件,感觉代码是挺杂的
      

  3.   

    或者监视父窗口的鼠标事件另外,鼠标事件不会在父子窗口中同时触发,还有,如果已经产生了MouseDown在MouseUp未发生前,MouseMove可能会脱离当前窗口继续运行.这些问题基本上都不好处理.
      

  4.   

    我不是要隐藏的,比如说一个Div层,然后想通过鼠标移入他就显示层,离开就隐藏层,不是像上面那代码那样的