默认工具提示不适用于我,因此我使用标签控件及其“可见”属性作为自定义工具提示,并在按下键时将其作为错误弹出窗口。因此,现在我尝试动态设置标签的位置(在我的情况下为textBox的位置),但它始终显示在表单的左上角。
方法如下:
void ShowCustomToolTip(string text, Control targetControl, int duration = 1000, int x = 0, int y = 0)
{
customToolTip.Text = text;
customToolTip.Visible = true;
// the crucial line that needs to be changed, I guess
customToolTip.Location = new Point(targetControl.Location.X + x, targetControl.Location.Y + y);
Set.Timer(duration);
customToolTip.Hide();
}
我该怎么做?谢谢!
问题是Control.Location
给您当前容器中的位置。您只需要相对于以下形式获取控件的绝对位置即可:
void ShowCustomToolTip(string text, Control targetControl, int duration = 1000, int x = 0, int y = 0)
{
customToolTip.Text = text;
customToolTip.Visible = true;
Point absoluteLocation = targetControl.FindForm().PointToClient(
targetcontrol.Parent.PointToScreen(control.Location));
// the crucial line that needs to be changed, I guess
customToolTip.Location = new Point(absoluteLocation.X + x, absoluteLocation.Y + y);
Set.Timer(duration);
customToolTip.Hide();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句