为什么我的 C++/CLI 工具提示不会出现?
我有一些验证代码,当输入错误值时,它应该显示控件的最大/最小值。
在我的构造函数中,我这样做:
m_wndToolTip = gcnew ToolTip(this->components);
m_wndToolTip->AutoPopDelay = 5000;
m_wndToolTip->InitialDelay = 10;
m_wndToolTip->ReshowDelay = 250;
m_wndToolTip->ShowAlways = true;// Force the ToolTip text to be displayed whether or not the form is active.
这是我的验证反射代码:
void MyGUI::IndicateValidationResult(Windows::Forms::Control^ control, bool isValid, String^ invalidReason)
{
// If the validation failed, make the background red. If not, turn it white.
if( isValid )
{
control->BackColor = Drawing::Color::White;
m_wndToolTip->Hide(control);
}
else
{
control->BackColor = Drawing::Color::LightCoral;
m_wndToolTip->Show(invalidReason, control);
}
}
...从文本框中的各种 ValueChanged
方法调用。我尝试过使用 show 以及 SetToolTip
和 active = true
的组合,但似乎没有任何效果。
我看到另一个有关工具提示的问题并尝试设置附近的标签在调用中显示,但这也不能解决问题。工具提示是我的 System::Windows::Forms::Form 派生表单中的一个成员变量,用于阻止它超出范围。
我错过了一些明显的东西吗?
I have some validation code which should display the max / min of a control when a bad value is entered.
In my constructor I do this:
m_wndToolTip = gcnew ToolTip(this->components);
m_wndToolTip->AutoPopDelay = 5000;
m_wndToolTip->InitialDelay = 10;
m_wndToolTip->ReshowDelay = 250;
m_wndToolTip->ShowAlways = true;// Force the ToolTip text to be displayed whether or not the form is active.
This is my validation reflection code:
void MyGUI::IndicateValidationResult(Windows::Forms::Control^ control, bool isValid, String^ invalidReason)
{
// If the validation failed, make the background red. If not, turn it white.
if( isValid )
{
control->BackColor = Drawing::Color::White;
m_wndToolTip->Hide(control);
}
else
{
control->BackColor = Drawing::Color::LightCoral;
m_wndToolTip->Show(invalidReason, control);
}
}
...which is called from varous ValueChanged
methods in my text boxes. I've tried using show and also a combination of SetToolTip
and active = true
and nothing seems to work.
I've seen another question asking about tooltips and have tried setting a nearby label in the call to show but that doesn't fix it either. The tooltip is a member variable in my System::Windows::Forms::Form
derived form to stop it going out of scope.
Am I missing something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我尝试时,你的代码工作得很好,我没有看到明显的错误。我这样称呼它,使用文本框的验证事件:
请注意,工具提示可能会很古怪。本机 Windows 组件有一个“功能”,可以防止工具提示在之前超时时再次显示。 ErrorProvider 组件是一个更好的鼠标陷阱来完成此任务。
Your code worked fine when I tried it, there's no obvious mistake that I can see. I called it like this, using a Validating event of a text box:
Beware that ToolTip can be cranky. The native Windows component has a "feature" that prevents a tooltip from showing again when it timed out before. The ErrorProvider component is a better mouse trap to get this done.