Laden...

Shortcut Manager mit Shortcuts wie Visual Studio

Erstellt von TheBrainiac vor 11 Jahren Letzter Beitrag vor 8 Jahren 14.448 Views
TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 11 Jahren
Shortcut Manager mit Shortcuts wie Visual Studio

Beschreibung:

Diese Komponente erkennt Shortcuts. Erstmal nichts besonderes, da das viele Komponenten können. Aber wie viele Komponenten gibt es, die Shortcuts wie die von Visual Studio (und auch längere) erkennen können?

z.B. folgende:

Alt + F4
Control, Shift + S
Control + E, D
Control + D, E, A, D, B, E, E, F
Control, Shift, Alt + Q, E
F3
MediaButtonPlay
ShortcutManager m_Shortcuts = new ShortcutManager();

m_Shortcuts.AddListener(myForm);

Erstellt einen Shortcut Manager und trägt eine Form als Listener ein.

m_Shortcuts.Actions.Add(Shortcut.Parse("Alt F4"), (s) => Close());
m_Shortcuts.Actions.Add(Shortcut.Parse("Control Shift S"), (s) => SaveAllDocuments());
m_Shortcuts.Actions.Add(Shortcut.Parse("Control S"), (s) => SaveCurrentDocument());
m_Shortcuts.Actions.Add(Shortcut.Parse("Control E D"), (s) => FormatText());
m_Shortcuts.Actions.Add(Shortcut.Parse("F3"), (s) => ShowSearchWindow());

Registriert ein paar Shortcuts.

m_Shortcuts.UnknownShortcut += (s) => SetInfoText("Shortcut '" + s + "' not recognized!");

Falls ein Shortcut erkannt, aber nicht registriert wurde.

Gruß,
Christian.

UPDATE:
2014-07-08: Problem mit @-Zeichen beseitigt. ((Vorher 77 Downloads)

Schlagwörter: short cut manager tasten kürzel visual studio

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`
P
50 Beiträge seit 2011
vor 9 Jahren

Hi,

wenn ich irgendwo auf der Form eine Textbox habe, und dort eine Mailadresse einfügen möchte, wird das @ ja als "Control, Alt + Q" erkannt.
Kann ich den Erkenner auch für bestimmt Shortcuts ausschalten?

Danke padde

TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 9 Jahren

Hallo. Habe das Problem beseitigt.

Du musst an deine TextBox zwei EventHandler mit folgendem Code anhängen:

private void textBox1_Enter(object sender, EventArgs e)
{
	m_Shortcuts.SuppressKeyPress = false;
	m_Shortcuts.SetHandled = false;
}

private void textBox1_Leave(object sender, EventArgs e)
{
	m_Shortcuts.SuppressKeyPress = true;
	m_Shortcuts.SetHandled = true;
}

Download im ersten Post angepasst.

Gruß, Christian.

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`
P
50 Beiträge seit 2011
vor 9 Jahren

Hi Christian,

funktionert super!!!

Vielen Dank
Patrick

P
50 Beiträge seit 2011
vor 8 Jahren

Hi Christian,

hab noch eine Frage.
Wenn ich in einer Textbox stehe, aber nur einen Handler für z.B. "Strg + Q" nutzen möchte, dieser auch registriert ist aber ein User jetzt "Strg + C" drückt, springt ja der ShortcutManager an, erkennt nix, kopiert auch nicht.
Schalte ich mit suppressKey beim Enter alles aus, funktionieren meine regisrierten Shortcuts ja nicht mehr.
Gibt es eine Möglichkeit, nur auf registrierte Shortcuts zu reagieren und den Rest quasi Windows zu "überlassen"?

Danke und Grüße
Patrick