写过一个这样的练习,你看是不是你想要的效果using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
xia=this.Bounds;
temp=xia;
hai=xia;
x=false;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(160, 245);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "hai";
this.Load += new System.EventHandler(this.Form1_Load);
this.MinimumSizeChanged += new System.EventHandler(this.Form1_MinimumSizeChanged);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.MouseLeave += new System.EventHandler(this.Form1_MouseLeave); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public System.Drawing.Rectangle xia,temp,hai;
public int iTop;
public bool x;
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
if(this.Top<0)
{
this.Top =0;
}
} private void Form1_MouseLeave(object sender, System.EventArgs e)
{
iTop=5-this.Height;
if(this.Top==0)
{
this.Top =1;
}
else if(this.Top==1)
{
this.Top =iTop;
}
} private void Form1_MinimumSizeChanged(object sender, System.EventArgs e)
{
iTop=5-this.Height;
this.Top=iTop;
} private void Form1_Load(object sender, System.EventArgs e)
{ } }
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
xia=this.Bounds;
temp=xia;
hai=xia;
x=false;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(160, 245);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "hai";
this.Load += new System.EventHandler(this.Form1_Load);
this.MinimumSizeChanged += new System.EventHandler(this.Form1_MinimumSizeChanged);
this.MouseEnter += new System.EventHandler(this.Form1_MouseEnter);
this.MouseLeave += new System.EventHandler(this.Form1_MouseLeave); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public System.Drawing.Rectangle xia,temp,hai;
public int iTop;
public bool x;
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
if(this.Top<0)
{
this.Top =0;
}
} private void Form1_MouseLeave(object sender, System.EventArgs e)
{
iTop=5-this.Height;
if(this.Top==0)
{
this.Top =1;
}
else if(this.Top==1)
{
this.Top =iTop;
}
} private void Form1_MinimumSizeChanged(object sender, System.EventArgs e)
{
iTop=5-this.Height;
this.Top=iTop;
} private void Form1_Load(object sender, System.EventArgs e)
{ } }
}
我想指出一个问题.就是,如果我在这个窗体上放一个LABEL,这个LABEL和窗体一样大,那么就不管用了.
也就是说,如果我有很多控件,拼起来和窗体一样大小的话,那么,你的这个方法就不行了.因为,我要给每个控件都写上MOUSEENTER和MOUSELEAVE.请问,有没有是用鼠标位置来进行判断的?
等待更好的答案.再次谢谢hanbinghai(海宁)
我的邮箱是:[email protected]
等待你回复.
楼主,你要是搞好的话,麻烦给我发一份,分享快乐哦[email protected]先谢~!~~~~~~~~~~~~~~~~~~~~~~~~
改变lable等控件的属性:Anchor,让它随窗体一起变化
对不起,我实在没有看懂你发给我的话的意思.能说的清楚一点么?
是Form的MouseLeave就不能用了,
不知道大哥们试过没有
[email protected]
是Form的MouseLeave就不能用了,""我也想知道这时候Form的MouseLeave要怎么办,还是检查鼠标
帮你顶吧……
不过,你发给我的代码是VC的,我对VC一点都不了解啊.还是很谢谢czhy()请大家帮帮我.谢谢.
http://community.csdn.net/Expert/topic/3417/3417339.xml?temp=.1954309
谢谢!十分感谢.问题解决了.我现在就结分.