我想实现一个拖到窗口上方自动隐藏,和鼠标放上去自动显示的功能
是这样的,我在mousemove 里判断    if( Top ==0)           
        this.Top = this.Top - this.Height + 5; 让他缩到上方,这样的话,如何才能够让他再次显示出来啊
   我在mouseenter里        if (this.Top < 0)
            {
                
                    ResizeToOrginal();  //还原成初始大小
            }这样就会出现死循环请大家提点一下~嘿嘿,还有怎么把贴出来的代码像其他人那样比较整齐的,带有c# code这样的?

解决方案 »

  1.   

    主要是判断top位置,定时查询鼠标位置实现显示
      

  2.   

    有个问题,
      this.Top = this.Top - this.Height + 5; 
    这样设置的话,窗体居然完全消失了,没辙~
      

  3.   

    你用top-height是<0的,如果height再大点,+5也<0,也就是说这条语句执行之后form的top值小于0,都不晓得显示到哪里去咯
      

  4.   

    其实,当你拖动窗体的时候,可以判断窗体当前的位置,当top值<=0的时候,就不能再拖动了,然后把height的值设为0就行了
      

  5.   

    不是设置this.top的值,而应该设置this.height的值,但不能像楼上说的,设为0,如果设为0,那么收起来后恐怕就感应不到mouseenter了,可以设置成一个>0的比较小的值,如:5应该可以的。
      

  6.   

    其实我这里的top就是0左右的数值了~
      

  7.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            int OrgHeight = 0;
            Timer T = new Timer();        public Form1()
            {
                InitializeComponent();            OrgHeight = this.Height;
                this.LocationChanged += new EventHandler(Form1_LocationChanged);
                this.MouseEnter += new EventHandler(Form1_MouseEnter);
                T.Interval = 100;
                T.Tick += new EventHandler(T_Tick);
            }        void T_Tick(object sender, EventArgs e)
            {
                if (!this.Bounds.Contains(Control.MousePosition) && this.Top == 0)
                {
                    HideForm();
                    T.Enabled = false;
                }
            }        void Form1_MouseEnter(object sender, EventArgs e)
            {
                if (this.FormBorderStyle == FormBorderStyle.None)
                {
                    this.FormBorderStyle = FormBorderStyle.Sizable;
                    this.Height = OrgHeight;
                    T.Enabled = true;
                }
            }        void Form1_LocationChanged(object sender, EventArgs e)
            {
                if (this.Top <= 0)
                {
                    HideForm();
                    T.Enabled = false;
                }
            }        private void HideForm()
            {
                this.Top = 0;
                this.FormBorderStyle = FormBorderStyle.None;
                this.Height = 1;
            }
        }
    }