public partial class frmOpacity : Form
{
private double _in = 1;//in form color
private double _out = 0.5;//leave form color
public frmOpacity()
{
InitializeComponent();
}
private void frmOpacity_MouseEnter(object sender, EventArgs e)
{
this.Opacity = _in;
}
private void frmOpacity_MouseLeave(object sender, EventArgs e)
{
if (Cursor.Position.X > this.Location.X && Cursor.Position.Y > this.Location.Y && Cursor.Position.X < this.Location.X + this.Width && Cursor.Position.Y < this.Location.Y + this.Height)
this.Opacity = _in;
else
this.Opacity = _out;
}
}
本文介绍了一个使用C#实现的窗体透明度动态调整功能。当鼠标进入窗体时,窗体透明度设为1;当鼠标离开时,根据鼠标位置决定是否保持全透明或者调整为半透明。该功能通过简单的条件判断实现。
1624

被折叠的 条评论
为什么被折叠?



