winform窗体问题

朝三慕四 2010-11-29 09:41:52
怎么样设置窗体属性使得窗体隐藏,当鼠标进入窗体范围时显示窗体....应该对窗体的哪个事件写代码...谢谢....
...全文
341 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
mycjzlove 2010-12-01
  • 打赏
  • 举报
回复
呵呵,路过。。
学习
朝三慕四 2010-12-01
  • 打赏
  • 举报
回复
哦,到现在估计可以结帖了...
谢谢大家了,我再仔细研究研究...
ZengHD 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 28 楼 lianaiqiong 的回复:]
这个好像只有隐藏没有显示呀,就是鼠标停留在窗体范围时显示出窗体...
[/Quote]

可以的,要加个时钟控件
朝三慕四 2010-12-01
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zenghd 的回复:]
C# code
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);

[DllImport("user32.dl……
[/Quote]
这个好像只有隐藏没有显示呀,就是鼠标停留在窗体范围时显示出窗体...
ZengHD 2010-11-30
  • 打赏
  • 举报
回复
 [DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);

[DllImport("user32.dll")]
public static extern bool GetCursorPos(out System.Drawing.Point lpPoint);

[DllImport("user32.dll")]
public static extern bool PtInRect(ref RECT lprc, System.Drawing.Point pt);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}

private RECT m_rect = new RECT();

private void Form1_MouseLeave(object sender, EventArgs e)
{
GetWindowRect(new HandleRef(this, this.Handle), out m_rect);
timer1.Enabled = true;
this.Hide();
}

private void timer1_Tick(object sender, EventArgs e)
{
if(m_rect.Left<=0 || m_rect.Top<=0 || m_rect.Right<=0 || m_rect.Bottom<=0)
return;

System.Drawing.Point point = new Point();
GetCursorPos(out point);
if (PtInRect(ref m_rect, point))
{
this.Visible = true;
timer1.Enabled = false;

m_rect.Left = 0;
m_rect.Top = 0;
m_rect.Right = 0;
m_rect.Bottom = 0;
}
}
cxx1997 2010-11-30
  • 打赏
  • 举报
回复
http://www.swigger.net/archives/114.html

这篇文章 对透明窗口的鼠标事件可能有帮助(需要你逆向思考了)
#blackheart 2010-11-30
  • 打赏
  • 举报
回复
你这不叫隐藏,是窗体的透明度
ZengHD 2010-11-30
  • 打赏
  • 举报
回复
窗体都隐藏了,还会有事件吗?
奔跑吧牛宝宝 2010-11-30
  • 打赏
  • 举报
回复
用计时器,每0.5秒判断当前鼠标的位置,和窗体的位置。
cxx1997 2010-11-30
  • 打赏
  • 举报
回复
没错,而且,Opacity 越小,MouseHover好像也越不敏感,你这个问题比较偏门,不怎么好搞
朝三慕四 2010-11-30
  • 打赏
  • 举报
回复
private void Form1_MouseLeave(object sender, EventArgs e)
{

this.Opacity = 0.1;//如果等于0,隐藏之后再不响应了
//MouseEnter,MouseHover,MouseMove
}


cxx1997 2010-11-30
  • 打赏
  • 举报
回复
挺有趣的问题

我试过了
private void Form1_MouseLeave(object sender, EventArgs e)
{ this.Opacity = 0.1; }
private void Form1_MouseHover(object sender, EventArgs e)
{ this.Opacity = 1; }

效果还可以
用MouseMove代替Hover事件更敏感



全栈深入 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lianaiqiong 的回复:]

C# code

private void Form1_MouseLeave(object sender, EventArgs e)
{

this.Opacity = 0;
}

private void Form1_MouseHover(object sender, EventArgs e)
……
[/Quote]

是不是窗体没有被激活,没有获得焦点
wy811007 2010-11-30
  • 打赏
  • 举报
回复
好像LZ以前提过这个问题。。
whowhen21 2010-11-30
  • 打赏
  • 举报
回复
就是的,Opacity 等于 0 ,就捕获不到那些事件了!0.1也看不到的~~!
********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
whowhen21 2010-11-30
  • 打赏
  • 举报
回复
就是的,Opacity 等于 0 ,就捕获不到那些事件了!0.1也看不到的~~!
********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
zhoupin 2010-11-30
  • 打赏
  • 举报
回复
关注中。。。
slmintg 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zenghd 的回复:]

C# code
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);

[DllImport("user32.dll")……
[/Quote]

要的应该就是这个了
garfieldzf 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 lianaiqiong 的回复:]
引用 14 楼 liyanyanfei 的回复:
是不是要实现像QQ一样窗体自动隐藏的效果?

差不多...
[/Quote]

http://www.cnblogs.com/hnNet/articles/1511232.html

仅供参考!
feixuyue 2010-11-30
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zenghd 的回复:]
C# code
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);

[DllImport("user32.dl……
[/Quote]
太NB了
加载更多回复(10)

110,525

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧