日期:2014-05-17  浏览次数:20756 次

Winform如何做像QQ天气一样,若天气窗体获得鼠标则不关闭,否则过会就关闭
Winform如何做像QQ天气一样,若天气窗体获得鼠标则不关闭,否则过会就关闭。并且像天气窗体一样无法移动。停靠在主窗体边上。
QQ 天气 停靠

------解决方案--------------------
主窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

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


        public Form2 m_frm2=null;  //天气窗体

        private void Form1_Load(object sender, EventArgs e)
        {
            this.MouseMove += Form1_MouseMove;
        }

        void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            this.Text = e.X + "," + e.Y;

            if (m_frm2 != null)
                  return;

            if (e.X > 100 && e.Y > 100 && e.X < 200 && e.Y < 200)  //主窗体(Form1)鼠标进入[100,100]-[200,200]区域显示天气窗体(Form2)
            {
                m_frm2 = new Form2();
                m_frm2.m_frm1 = this;               
                m_frm2.Show();

            }
        }

  

    }
}



天气窗体代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            Ini