2010-03-23 116 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組件是一個更好的鼠標陷阱來完成這件事。

相關問題