110,536
社区成员
发帖
与我相关
我的任务
分享
this.Top = this.Top - this.Height + 5;
原来是这样的
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;
}
}
}