【问题标题】:How to set the location of an owner draw tooltip?如何设置所有者绘制工具提示的位置?
【发布时间】:2012-08-03 11:12:32
【问题描述】:

在运行时,我创建了一个所有者绘制工具提示,在弹出事件中设置我的工具提示窗口的大小,并在绘制事件中设置文本。

public void NewLabel(string aText)
{
  ToolTip tt = new ToolTip();
  tt.Popup += new PopupEventHandler(tt_Popup);
  tt.Draw += new DrawToolTipEventHandler(tt_Draw);

  tt.BackColor = Color.White;
  tt.AutomaticDelay = 100;
  tt.AutoPopDelay = 35000;
  tt.IsBalloon = false;
  tt.OwnerDraw = true;
  tt.SetToolTip(aLabel, sToolTip); 
}

public void tt_Popup(object sender, PopupEventArgs e)
{
  e.ToolTipSize = new Size(e.ToolTipSize.Width + 300, e.ToolTipSize.Height + 200);
}

public void tt_Draw(object sender, DrawToolTipEventArgs e)
{
  e.DrawBackground();
  e.DrawBorder();
}

这很好用,但问题是,如果我的工具提示绘制事件由屏幕底部的控件触发,则工具提示不会像标准工具提示那样自动设置在可视区域中。

有什么想法吗?

【问题讨论】:

  • 它是框架 3.5 上的 WinForms 应用

标签: c# .net winforms


【解决方案1】:

工具提示将检查其矩形是否在屏幕上,并在调用 Show 期间使用其现有大小自行移动。这发生在 Popup 之前。该框架确实会查看您返回的工具提示大小,但它用于调整宽度和高度,而不是在它不再适合时重新定位窗口。

我没有尝试过,但我认为您必须自己移动弹出窗口以确保它保持在屏幕上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    相关资源
    最近更新 更多