通过反射触发一下GcDate的Validating事件应该就可以,参见这段代码- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- var shortcuts = this.gcShortcut1.GetShortcuts(gcDate1);
- shortcuts.Add(Keys.Enter, new MethodInvoker(ValidateGcDate));
- }
- public void ValidateGcDate()
- {
- var focusedControl = GetFocusedControl(this) as GrapeCity.Win.Editors.GcDate;
- if (focusedControl == null)
- {
- return;
- }
- MethodInfo mi = focusedControl.GetType().GetMethod("PerformControlValidation", BindingFlags.Instance | BindingFlags.NonPublic);
- if (mi != null)
- {
- mi.Invoke(focusedControl, new object[] { true });
- }
- }
- private static Control GetFocusedControl(Control root)
- {
- if (!root.ContainsFocus)
- {
- return null;
- }
- if (root.Focused)
- {
- return root;
- }
- foreach (var child in root.Controls)
- {
- var focusedControl = GetFocusedControl(child as Control);
- if (focusedControl != null)
- {
- return focusedControl;
- }
- }
- return null;
- }
- }
复制代码 |