c#控件的自动显示与隐藏

qlf2008 2009-12-03 11:00:02
目的是这样的,当鼠标离开Button控件时,控件自动隐藏,当鼠标到达Button控件上时再自动显示!
原本想用鼠标进入控件范围的事件来做的,可是好像当控件的可见性甚至为false以后鼠标进入控件的位置后引发不了mouseEnter事件啊!请教!
...全文
843 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazydoglzc 2009-12-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wartim 的回复:]
C# codeusing 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 Windows?-
[/Quote]

学习了.这个好!
波导终结者 2009-12-03
  • 打赏
  • 举报
回复
9楼B.Visible = B.Bounds.Contains(e.Location );的方法更好,你可以用他的这个
qlf2008 2009-12-03
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 alifriend 的回复:]
C# codeprivatevoid button1_MouseLeave(object sender, EventArgs e)
{
button1.Visible=false;
}privatevoid Form1_MouseMove(object sender, MouseEventArgs e)
{if (e.X> b?-
[/Quote]
谢谢,这个方法可行。已经成功实现了!分给你了!
wartim 2009-12-03
  • 打赏
  • 举报
回复
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 WindowsFormsApplication5
{
public partial class Form1 : Form
{
Button B = new Button();

public Form1()
{
InitializeComponent();

B.Parent = this;
B.Visible = false;

this.MouseMove += new MouseEventHandler(Form1_MouseMove);
}

void Form1_MouseMove(object sender, MouseEventArgs e)
{
B.Visible = B.Bounds.Contains(e.Location );
}
}
}
qlf2008 2009-12-03
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 solawing 的回复:]
在父容器的鼠标移动事件中判断鼠标是否进入button控件的范围,进入了就显示
[/Quote]
恩,这个我也想过的。要创建一个线程不断的判断么>?还是用timer控件啊?这两个都不熟悉。我知道非UI线程不可以直接操作UI线程里面的控件的
波导终结者 2009-12-03
  • 打赏
  • 举报
回复
        private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Visible = false;
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X > button1.Left && e.X < button1.Right && e.Y > button1.Top && e.Y < button1.Bottom)
button1.Visible = true;
}
kantaguo 2009-12-03
  • 打赏
  • 举报
回复
通过鼠标的相对位置来判断是否在button上,然后再响应相应的处理程序
qlf2008 2009-12-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 crazydoglzc 的回复:]
C# codeprivatevoid button1_MouseLeave(object sender, EventArgs e)
{
button1.Enabled=false;
}
[/Quote]
我要是隐藏,不是不可用啊。
SolaWing 2009-12-03
  • 打赏
  • 举报
回复
在父容器的鼠标移动事件中判断鼠标是否进入button控件的范围,进入了就显示
crazydoglzc 2009-12-03
  • 打赏
  • 举报
回复
        private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Enabled = false;
}
qlf2008 2009-12-03
  • 打赏
  • 举报
回复
Button控件有透明度?
我姓区不姓区 2009-12-03
  • 打赏
  • 举报
回复
设置透明度行不行

110,566

社区成员

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

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

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