/// <summary> /// Find correct callback and corresponding label /// </summary> /// <param name="tb"></param> /// <param name="cb"></param> /// <param name="lb"></param> private void PrepareForHotkey(TextBox tb, out HotKeys.HotKeyCallBackHandler cb, out Label lb) { /* * XXX: The labelName, TextBoxName and callbackName * must follow this rule to make use of reflection * * <BaseName><Control-Type-Name> */ if (tb == null) { throw new ArgumentNullException(nameof(tb)); } var pos = tb.Name.LastIndexOf("TextBox", StringComparison.OrdinalIgnoreCase); var rawName = tb.Name.Substring(0, pos); var labelName = rawName + "Label"; var callbackName = rawName + "Callback"; var callback = HotkeyCallbacks.GetCallback(callbackName); if (callback == null) { throw new Exception($"{callbackName} not found"); } cb = callback as HotKeys.HotKeyCallBackHandler; var label = GetFieldViaName(GetType(), labelName, this); if (label == null) { throw new Exception($"{labelName} not found"); } lb = label as Label; }
private static void UnregPrevHotkey(HotKeys.HotKeyCallBackHandler cb) { GlobalHotKey.HotKey prevHotKey; if (HotKeys.IsCallbackExists(cb, out prevHotKey)) { // unregister previous one HotKeys.UnRegist(prevHotKey); } }
public static bool UnregExistingHotkey(HotKeys.HotKeyCallBackHandler cb) { HotKey existingHotKey; if (IsCallbackExists(cb, out existingHotKey)) { // unregister existing one Unregister(existingHotKey); return(true); } else { return(false); } }