Cla*_*nus 1 vb.net errorprovider blink visual-studio winforms
ErrorProvider生成的红色图标闪烁6次.我希望能够将它设置为闪烁两次.
我遇到的唯一眨眼属性是,BlinkRate并且BlinkStyle都不会影响眨眼数量.
码:
Public Class Form1
Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If Not IsNumeric(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "Numeric input only!")
Else
ErrorProvider1.SetError(TextBox1, "")
End If
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
这在Winforms源代码中是硬编码的.
如果你真的想,它可以搞砸.反射可用于访问私人成员.通常风险有些,但Winforms代码已经稳定很长时间了,不会再改变了.我将发布C#版本,你可以很容易地将它翻译成VB:
using System.Reflection;
...
public static void ReportError(ErrorProvider provider, Control control, string text) {
if (provider.GetError(control) == text) return;
provider.SetError(control, text);
// Dig out the "items" hash table to get access to the ControlItem for the control
var fi = typeof(ErrorProvider).GetField("items", BindingFlags.NonPublic | BindingFlags.Instance);
var ht = (System.Collections.Hashtable)(fi.GetValue(provider));
var ci = ht[control];
// Patch the ControlItem.blinkPhase field to lower it to 2 blinks
var fi2 = ci.GetType().GetField("blinkPhase", BindingFlags.NonPublic | BindingFlags.Instance);
if ((int)fi2.GetValue(ci) > 4) fi2.SetValue(ci, 4);
}
Run Code Online (Sandbox Code Playgroud)
工作正常,风险低.