当我试图为OxyPlot的自定义命中测试系统创建一个自定义工具提示系统时,我遇到了这个问题。示例代码如下所示,它在处理事件Form.Click
时自动移动鼠标光标以显示问题。
复制步骤
创建一个空窗体(示例大小: 500x500)
H 112
隐藏工具提示<代码>H 213<代码>H 114等待几秒钟<代码>H 215<代码>H 116显示工具提示字符串两行“测试123456789\n n\n line”
\n“
一秒内,一行"test 1“字符串也显示在最后一个光标位置。
屏幕记录(问题在其中不可见)
代码
public partial class Form1 : Form
{
private ToolTip toolTip;
public Form1()
{
InitializeComponent();
Click += Form1_Click;
toolTip = new ToolTip();
toolTip.UseAnimation = false;
toolTip.UseFading = false;
}
private void Form1_Click(object sender, EventArgs e)
{
_ = DoIt();
}
private async Task DoIt()
{
Point pos = PointToClient(MousePosition);
pos.Y += Cursor.Current.Size.Height;
// Without the -2000, the duration of the tooltip is too long (because of the fade-in/out animation)
toolTip.Show("test", this, pos, Math.Max(0, toolTip.AutoPopDelay - 2000));
await Task.Delay(5000);
Cursor.Position = new Point(Cursor.Position.X + 100, Cursor.Position.Y);
toolTip.Hide(this);
Application.DoEvents();
await Task.Delay(5000);
pos = PointToClient(MousePosition);
pos.Y += Cursor.Current.Size.Height;
toolTip.Show("test 123456789\n\nanother line", this, pos, Math.Max(0, toolTip.AutoPopDelay - 2000));
}
}
我试过的
我做了上面的代码样本来显示问题..。我也在StackOverflow上搜索过,没有找到什么可以帮助我的东西。
预期结果
第二个工具提示显示与第一个工具提示类似,没有前一个工具提示字符串的闪烁图像。
实际效果
旧工具提示字符串在新工具提示字符串的位置闪烁。它不是很明显,主要是当动画启用,但它仍然是丑陋的我。
可能解决办法的想法
async-await.
系统配置
我使用这个.NET框架v4.5.2,但是我用.NET框架v4.7.2尝试了上面的代码,它也有同样的问题。我使用Windows 10和VS 2019。
谢谢。
发布于 2021-08-04 13:00:54
我可能会晚一点去参加派对,但无论如何。
解决方案是,每次您想要显示一个时,只需实例化一个新的ToolTip组件。就这样,不再弹前一段文字了。(您可能需要处理旧的,以确保没有泄漏。)
https://stackoverflow.com/questions/58267337
复制相似问题