简单?如何鼠标进入了窗体? 窗体有一些控件:Form -> Dock Fill Panel-> Dock Left Label -> Dock Fill Label.现在我想判断鼠标是否在窗体之上,请问该怎么解决呢?有没有简单的方法?简单的MouseEnter/MouseLeave是没有用的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Form -> Dock Fill Panel-> Dock Left Label -> Dock Fill Label结构应该是这样 那不是每一个控件都要 MouseMove?该死的空格:Form -> Dock Fill Panel-> Dock Left Label------------------------> Dock Fill Label 用timer吧 [DllImport("user32.dll")] private static extern bool GetCursorPos(out Point p); private void timer1_Tick(object sender, EventArgs e) { Point p; GetCursorPos(out p); if (p.X >= this.Left && p.X <= this.Right && p.Y >= this.Top && p.Y <= this.Bottom) { MessageBox.Show("ok"); } } Timer timer = new Timer();public Form1(){ InitializeComponent(); timer.Interval = 50; timer.Tick += delegate { double opacity = this.Bounds.Contains(Cursor.Position) ? 0.9 : 0.4; if( this.Opacity != opacity ) this.Opacity = opacity; }; timer.Start();} 我也有考虑一个 timer,但是最终还是否决了。觉得这个是“不行中的办法”。 木办法了吗~以前也有google类似的问题,但最终是没有答案。 应该不难吧,通过 MousePosition获得鼠标相对于屏幕的坐标,再通过窗体的位置和大小获得窗体的矩形区域,看鼠标坐标是否在其中不就行了吗? int xl = 0; int yl = 0; private void timer1_Tick(object sender, EventArgs e) { xl = MousePosition.X; yl = MousePosition.Y; if (xl < this.Location.X + this.Width && xl > this.Location.X) { if (yl > this.Location.Y && yl < this.Location.Y + this.Height) { this.Opacity = 1; } else { this.Opacity = 0.5; } } else { this.Opacity = 0.5; } }试了下 ,确实可以的 求帮助,为什么这个循环的i会超出255 C/S结构怎样解决多客户端的业务并发? ——求C# 相关外文+ 翻译一份!!! 我想直接生成本机代码,而不是中间代码要怎么做? 大家帮我看看log4net 配置不管用啊? 动态创建控件以后,绑定事件时出现问题。急!!! .net到底是什么意思啊,是不是www.xxx.net后面的啊? 谁做过上传附件的例子啊,保存到数据库,给分 对于绑定数据源的datagridview如何实时更新数据 求教各位大神,C#怎么用TChart控件实现缩小功能啊? 高手快来解决!!! 【急】C# 字符串 的处理?
-> Dock Fill Label结构应该是这样
Form -> Dock Fill Panel-> Dock Left Label
------------------------> Dock Fill Label
private static extern bool GetCursorPos(out Point p); private void timer1_Tick(object sender, EventArgs e)
{
Point p;
GetCursorPos(out p);
if (p.X >= this.Left && p.X <= this.Right && p.Y >= this.Top && p.Y <= this.Bottom)
{
MessageBox.Show("ok");
}
}
public Form1()
{
InitializeComponent(); timer.Interval = 50;
timer.Tick += delegate
{
double opacity = this.Bounds.Contains(Cursor.Position) ? 0.9 : 0.4;
if( this.Opacity != opacity ) this.Opacity = opacity;
};
timer.Start();
}
觉得这个是“不行中的办法”。
int yl = 0;
private void timer1_Tick(object sender, EventArgs e)
{
xl = MousePosition.X;
yl = MousePosition.Y;
if (xl < this.Location.X + this.Width && xl > this.Location.X)
{
if (yl > this.Location.Y && yl < this.Location.Y + this.Height)
{
this.Opacity = 1;
}
else
{
this.Opacity = 0.5;
}
}
else
{
this.Opacity = 0.5;
}
}试了下 ,确实可以的