在 ToolTip.Show 上设置 x 和 y 也会以某种方式设置持续时间?
Setting x & y on ToolTip.Show somehow sets duration as well?
当我像下面这样调用 ToolTip.Show() 时;
ToolTip.Show(Message, MyControl);
一切正常,它显示并在 MyControl 失去焦点时消失。但是 ToolTip 的位置在 MyControl 之上,所以我想添加一个偏移量;
ToolTip.Show(Message,MyControl,10,-20);
工具提示确实按我想要的方式定位,它在悬停时显示,但在 MyControl 失去焦点时不再消失。该行为类似于将持续时间设置得非常高。
当我查看ToolTip.Show()定义时,其中一种调用方式是这样的;
public void Show(string text, IWin32Window window, int x, int y);
那么,当我只添加 x 和 y 偏移量而没有触摸持续时间时,ToolTip 怎么会突然停止消失?
完整代码下方:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WFA
{
public class Form1 : Form
{
public Form1()
{
UC UC = new UC();
this.Controls.Add(UC);
}
}
public class UC : UserControl
{
String Message = "Hello!";
PictureBox MyControl = new PictureBox();
ToolTip ToolTip = new ToolTip();
public UC()
{
MyControl.ImageLocation = "http://i.stack.imgur.com/CR5ih.png";
MyControl.Location = new Point(100, 100);
this.Controls.Add(MyControl);
MyControl.MouseHover += ShowToolTip;
}
private void ShowToolTip(object sender, EventArgs e)
{
ToolTip.Show(Message, MyControl,10,-20); // this will never disappear??
//ToolTip.Show(Message, MyControl); // this disappears after leaving
}
}
}
你应该使用
ToolTip.Show(字符串文本, IWin32Window window, int x, int y, int duration);
默认情况下,如果您不指定任何"Timeout",工具提示将仅在停用父窗体时隐藏。
如果您想在鼠标离开控件时隐藏工具提示,您必须通过调用 ToolTip.Hide
.
手动完成
public UC()
{
BorderStyle = BorderStyle.FixedSingle;
MyControl.ImageLocation = "http://i.stack.imgur.com/CR5ih.png";
MyControl.Location = new Point(100, 100);
this.Controls.Add(MyControl);
MyControl.MouseHover += ShowToolTip;
//Subscribe MouseLeave and hide the tooltip there
MyControl.MouseLeave += MyControl_MouseLeave;
}
void MyControl_MouseLeave(object sender, EventArgs e)
{
ToolTip.Hide(MyControl);
}
当我像下面这样调用 ToolTip.Show() 时;
ToolTip.Show(Message, MyControl);
一切正常,它显示并在 MyControl 失去焦点时消失。但是 ToolTip 的位置在 MyControl 之上,所以我想添加一个偏移量;
ToolTip.Show(Message,MyControl,10,-20);
工具提示确实按我想要的方式定位,它在悬停时显示,但在 MyControl 失去焦点时不再消失。该行为类似于将持续时间设置得非常高。
当我查看ToolTip.Show()定义时,其中一种调用方式是这样的;
public void Show(string text, IWin32Window window, int x, int y);
那么,当我只添加 x 和 y 偏移量而没有触摸持续时间时,ToolTip 怎么会突然停止消失?
完整代码下方:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WFA
{
public class Form1 : Form
{
public Form1()
{
UC UC = new UC();
this.Controls.Add(UC);
}
}
public class UC : UserControl
{
String Message = "Hello!";
PictureBox MyControl = new PictureBox();
ToolTip ToolTip = new ToolTip();
public UC()
{
MyControl.ImageLocation = "http://i.stack.imgur.com/CR5ih.png";
MyControl.Location = new Point(100, 100);
this.Controls.Add(MyControl);
MyControl.MouseHover += ShowToolTip;
}
private void ShowToolTip(object sender, EventArgs e)
{
ToolTip.Show(Message, MyControl,10,-20); // this will never disappear??
//ToolTip.Show(Message, MyControl); // this disappears after leaving
}
}
}
你应该使用 ToolTip.Show(字符串文本, IWin32Window window, int x, int y, int duration);
默认情况下,如果您不指定任何"Timeout",工具提示将仅在停用父窗体时隐藏。
如果您想在鼠标离开控件时隐藏工具提示,您必须通过调用 ToolTip.Hide
.
public UC()
{
BorderStyle = BorderStyle.FixedSingle;
MyControl.ImageLocation = "http://i.stack.imgur.com/CR5ih.png";
MyControl.Location = new Point(100, 100);
this.Controls.Add(MyControl);
MyControl.MouseHover += ShowToolTip;
//Subscribe MouseLeave and hide the tooltip there
MyControl.MouseLeave += MyControl_MouseLeave;
}
void MyControl_MouseLeave(object sender, EventArgs e)
{
ToolTip.Hide(MyControl);
}