我是想在鼠标移过控件时,用ToolTip显示控件内容。用了MouseMove事件editor.MouseMove += new MouseEventHandler(showTip);private void showTip(object sener, MouseEventArgs e)
{
if (e.X > control.Location.X && e.X < control.Location.X + control.Width && e.Y > control.Location.Y && e.Y < control.Location.Y + control.Height)
toolTip1.Show("AAAAAAAAAAAAAAAAAA",control);
}
这样显示的不对呀
请高手指教
{
if (e.X > control.Location.X && e.X < control.Location.X + control.Width && e.Y > control.Location.Y && e.Y < control.Location.Y + control.Height)
toolTip1.Show("AAAAAAAAAAAAAAAAAA",control);
}
这样显示的不对呀
请高手指教
TabIndex="18" Text="新增客户" ToolTip="新增客户资料,确认请按保存按钮" Width="62px" />
鼠标放上去ToolTip直接就显示“新增客户资料,确认请按保存按钮”文字啊,还要操作啥?
if(button1.Bounds.Contains(e.x,e.y))
{
this.button1.BackColor=Color.Red;
}
else
{
this.button1.BackColor=Color.yellow;
}
执行的效果不对啊,好像是if下面的代码不执行,什么原因啊??
private void ctl_MouseEnter(object sender, EventArgs e)
{
label1.Text=((Control)sender).Text;
}
鼠标移到TextBox控件中,就找不到鼠标的坐标了??
鼠标移到TextBox控件中,就不触发MouseMove事件了
第二种办法:是在每个动态加载的控件上都添加MouseHover或是其他的鼠标事件上动态的添加一个Tooltip这样能动态的添加提示信息。
还有一种最笨的办法是:获得鼠标在桌面上的坐标coordenate,然后换算到当前控件的父控件上的坐标。然后比较当前的鼠标坐标和当前控件的Location.判断当前的鼠标是否在该控件上。然后动态的画一个Lable或是Richtextbox框,显示动态的信息。然后动态的清除你添加的控件。动态清除的方法可以自己做一个定时器,显示定时的时间。或是在Lable框或是RichTextBox框中MouseLeave事件中添加自销毁的代码。
private void text_ShowTooltips()
{
Panel panel = new Panel()
{
Location = new Point(0, 0),
Size = this.ClientSize
}; this.Controls.Add(panel); panel.Controls.AddRange(new Control[] {
new Button() { Location=new Point(100,100), Text="Button1", AccessibleDescription="This is Button1" },
new Button() { Location=new Point(100,150), Text="Button2", AccessibleDescription="This is Button2" },
new Button() { Location=new Point(100,200), Text="Button3", AccessibleDescription="This is Button3" },
new Button() { Location=new Point(100,250), Text="Button4", AccessibleDescription="This is Button4" },
new Button() { Location=new Point(100,300), Text="Button5", AccessibleDescription="This is Button5" },
}); ToolTip tips = new ToolTip(); foreach (Control ctrl in panel.Controls)
{
if (ctrl is Button && ctrl.AccessibleDescription != "")
{
tips.SetToolTip(ctrl, ctrl.AccessibleDescription);
}
} panel.BringToFront();
}
最后还是要控件强转成原始的类型。
然后用toolTip.SetToolTip(原始控件类型,string);原来就这么容易,
调坐标对我来说确实太难了。。
非要代码写的话,就上面那种 toolTip.SetToolTip(原始控件类型,string);