カスタム検証コンポーネント(GcCustomValidator)は、独自の検証処理と検証結果を表示する通知機能(CustomeValidateContext)をGcTextBox等のテキスト入力用のコントロールに拡張するコンポーネントです。
GcCustomValidatorオブジェクトは、任意のコントロールに対し独自の検証処理や検証タイミングの設定を行います
メソッド
validator.SetValidatingMethod(gcTextBox1,
Sub(context)
Dim length = context.Control.Text.Length
If length <= 3 Then
context.IsValid = False
context.EnableTipNotify = True
context.TipNotify.ToolTipTitle = "エラーメッセージ"
context.TipNotify.ToolTipIcon = ToolTipIcon.Error
context.TipNotify.ToolTipText = "3文字以上入力してください。"
Else
context.IsValid = True
End If
End Sub)
validator.SetSupportRealTimeValidating(gcTextBox1, True)
var validator = new GcCustomValidator();
validator.SetValidatingMethod(gcTextBox1, (context) =>
{
var length = context.Control.Text.Length;
if (length <= 3)
{
context.IsValid = false;
context.EnableTipNotify = true;
context.TipNotify.ToolTipTitle = "エラーメッセージ";
context.TipNotify.ToolTipIcon = ToolTipIcon.Error;
context.TipNotify.ToolTipText = "3文字以上入力してください。";
}
else
{
context.IsValid = true;
}
});
validator.SetSupportRealTimeValidating(gcTextBox1, true);
GcBallonTipNotifyオブジェクトは、検証結果をバルーンチップに通知します。
プロパティ
' GcBallonTipNotifyを有効にします。
context.EnableGcBallonTipNotify = True
' BalloonTipInformationオブジェクトのTextにメッセージを設定します。
context.GcBalloonTipNotify.BalloonTipInformation.Text = "3文字以上入力してください。"
' バルーンチップの表示位置を指定します。
context.GcBalloonTipNotify.TipPosition = TipPosition.BottomRight
' バルーンチップの周辺に影を表示します。
context.GcBalloonTipNotify.ShowShadow = True
' バルーンチップのフェード効果を有効にします。
context.GcBalloonTipNotify.UseFading = False
// GcBallonTipNotifyを有効にします。
context.EnableGcBallonTipNotify = true;
// BalloonTipInformationオブジェクトのTextにメッセージを設定します。
context.GcBalloonTipNotify.BalloonTipInformation.Text = "3文字以上入力してください。";
// バルーンチップの表示位置を指定します。
context.GcBalloonTipNotify.TipPosition = TipPosition.BottomRight;
// バルーンチップの周辺に影を表示します。
context.GcBalloonTipNotify.ShowShadow = true;
// バルーンチップのフェード効果を有効にします。
context.GcBalloonTipNotify.UseFading = false;
CustomValidateContextオブジェクトは、コントロールに対し検証結果の通知を行います。
プロパティ
If context.Control.Text.Length < 3 Then
context.IsValid = False
' GcBallonTipNotifyを有効にします。
context.EnableGcBallonTipNotify = True
' BalloonTipInformationオブジェクトのTextにメッセージを設定します。
context.GcBalloonTipNotify.BalloonTipInformation.Text = "3文字以上入力してください。"
' ThreeStateBorderNotifyを有効にします。
context.EnableThreeStateBorderNotify = True
' 枠線の色を設定します。
context.ThreeStateBorderNotify.InvalidLineColor = Color.Red
' FocusProcessを有効にします。
context.EnableFocusProcess = True
' フォーカス移動の抑制を設定します。
context.FocusProcess.PreventFocusLeave = True
' EnableIconを有効にします。
context.EnableIconNotify = True
' アイコンを設定します。
context.IconNotify.Icon = New Icon(".\Sample1.ico")
' EnableLineNotifyを有効にします。
context.EnableLineNotify = True
' 下線の色を設定します。
context.LineNotify.LineColor = Color.Yellow
' EnableSoundNotifyを有効にします。
context.EnableSoundNotify = True
' 警告音を設定します。
context.SoundNotify.SoundType = SystemSoundType.Beep
' EnableTipNotifyを有効にします。
context.EnableTipNotify = True
' ツールチップのテキストを設定します。
context.TipNotify.ToolTipText = "3文字以上入力してください。"
' EnableColorNotifyを有効にします。
context.EnableColorNotify = True
' 背景色を設定します。
context.ColorNotify.InvalidBackColor = Color.Blue
' EnableValueProcessを有効にします。
context.EnableValueProcess = True
' 入力値の制御を設定します。
context.ValueProcess.ValueProcessOption = ValueProcessOption.Keep
Else
context.IsValid = True
' EnableThreeIconBorderNotifyを有効にします。
context.EnableThreeIconBorderNotify = True
' 検証成功時のアイコンを設定します。
context.ThreeStateIconNotify.ValidIcon = New Icon(".\Sample2.ico")
End If
if (context.Control.Text.Length < 3)
{
context.IsValid = false;
// GcBallonTipNotifyを有効にします。
context.EnableGcBallonTipNotify = true;
// BalloonTipInformationオブジェクトのTextにメッセージを設定します。
context.GcBalloonTipNotify.BalloonTipInformation.Text = "3文字以上入力してください。";
// ThreeStateBorderNotifyを有効にします。
context.EnableThreeStateBorderNotify = true;
// 枠線の色を設定します。
context.ThreeStateBorderNotify.InvalidLineColor = Color.Red;
// FocusProcessを有効にします。
context.EnableFocusProcess = true;
// フォーカス移動の抑制を設定します。
context.FocusProcess.PreventFocusLeave = true;
// EnableIconを有効にします。
context.EnableIconNotify = true;
// アイコンを設定します。
context.IconNotify.Icon = new Icon(@".\Sample1.ico");
// EnableLineNotifyを有効にします。
context.EnableLineNotify = true;
// 下線の色を設定します。
context.LineNotify.LineColor = Color.Yellow;
// EnableSoundNotifyを有効にします。
context.EnableSoundNotify = true;
// 警告音を設定します。
context.SoundNotify.SoundType = SystemSoundType.Beep;
// EnableTipNotifyを有効にします。
context.EnableTipNotify = true;
// ツールチップのテキストを設定します。
context.TipNotify.ToolTipText = "3文字以上入力してください。";
// EnableColorNotifyを有効にします。
context.EnableColorNotify = true;
// 背景色を設定します。
context.ColorNotify.InvalidBackColor = Color.Blue;
// EnableValueProcessを有効にします。
context.EnableValueProcess = true;
// 入力値の制御を設定します。
context.ValueProcess.ValueProcessOption = ValueProcessOption.Keep;
}
else
{
context.IsValid = true;
// EnableThreeIconBorderNotifyを有効にします。
context.EnableThreeIconBorderNotify = true;
// 検証成功時のアイコンを設定します。
context.ThreeStateIconNotify.ValidIcon = new Icon(@".\Sample2.ico");
}