为什么我的 C++/CLI 工具提示不会出现?

发布于 2024-08-27 00:29:13 字数 1219 浏览 4 评论 0原文

我有一些验证代码,当输入错误值时,它应该显示控件的最大/最小值。

在我的构造函数中,我这样做:

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 以及 SetToolTipactive = 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空‖城人不在 2024-09-03 00:29:13

当我尝试时,你的代码工作得很好,我没有看到明显的错误。我这样称呼它,使用文本框的验证事件:

bool ok;

System::Void textBox1_Validating(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
  e->Cancel = !ok;
  IndicateValidationResult(textBox1, ok, "invalid");
  ok = !ok;
}

请注意,工具提示可能会很古怪。本机 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:

bool ok;

System::Void textBox1_Validating(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
  e->Cancel = !ok;
  IndicateValidationResult(textBox1, ok, "invalid");
  ok = !ok;
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文