日期:2014-05-18  浏览次数:20976 次

怎样能够让鼠标在窗体外点击,窗体自动关闭或隐藏?
怎样能够让鼠标在窗体外点击,窗体自动关闭或隐藏?

------解决方案--------------------
C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication291
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Timer T = new Timer();
            T.Interval = 100;
            T.Tick += new EventHandler(T_Tick);
            T.Enabled = true;
        }

        void T_Tick(object sender, EventArgs e)
        {
            if (!this.Bounds.Contains(Control.MousePosition)
                &&Control.MouseButtons==MouseButtons.Left  )
                Close();
        }
    }
}

------解决方案--------------------
C# code

 public Form4()
        {
            InitializeComponent();

            Timer T = new Timer();
            T.Interval = 100;
            T.Tick += new EventHandler(T_Tick);
            T.Enabled = true;
        }


        void T_Tick(object sender, EventArgs e)
        {
            if (!this.Bounds.Contains(Control.MousePosition))
                Text = Control.MousePosition.X.ToString();
            
                //Close();
        }