2010-03-23 118 views
1

我有一些验证码,它应该显示输入错误值时控件的最大/最小值。为什么我的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); 
    } 
} 

...这是从我的文本框varous ValueChanged方法调用。我试过使用显示,并且还有SetToolTipactive = true的组合,但似乎没有任何效果。

我见过another question asking about tooltips,并试图在调用中设置附近的标签来显示,但并没有解决它。工具提示是我的System::Windows::Forms::Form派生形式中的成员变量,用于阻止它超出范围。

我错过了一些明显的东西吗?

回答

1

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

bool ok; 

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

请注意,工具提示可能会胡思乱想。本机Windows组件具有一个“功能”,可防止以前超时时再次显示工具提示。 ErrorProvider组件是一个更好的鼠标陷阱来完成这件事。

相关问题