Autor Beitrag
Talemantros
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Di 11.11.14 22:15 
Hallo nochmal,

mit eurer Hilfe hatte ich es ja so gelernt, dass ich ein UserControl erstelle, welches ich zur Laufzeit in eine Winform laden und mit Dock.Fill anzeigen lasse.

Nun würde ich gern das Winform mit "Escape" beenden können.

Die Eigenschaft "CancelButton" geht aber nur für Buttons auf der Winform und nicht in der UserControl.

Wie kann ich da vorgehen?

Danke

Gruß
Daniel
Yankyy02
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 138
Erhaltene Danke: 21

Win 11 x64
C# (VS 2022 - Rider)
BeitragVerfasst: Di 11.11.14 22:48 
Hallo Talemantros,

wenn du Forms benutzt musst du die KeyPreview Eigenschaft der Form auf true setzen damit die Form Tastatur eingaben entgegen nimmt. Anschlißend kannst mit
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
     if (e.KeyCode == Keys.Escape)
     {
          this.Close();
     }
}


die Form schließen.

LG
Gery

_________________
the quiter you become, the more you are able to hear
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Mi 12.11.14 15:31 
Hey Yankyy02,
vielen Dank für den Tipp.
Werde ich nachher sofort austesten, wenn ich zu Hause bin.

Gruß
Daniel
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 12.11.14 18:11 
Was spricht gegen den Windows Standard ALT+F4?
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 15.11.14 12:42 
Hallo Ralf,
ALT+F4 würde ja die ganze Anwendung beenden.
Ich möchte nur geöffnete Forms innerhalb der Hauptanwendung mit Escape schließen können.

Gruß
Daniel
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 15.11.14 12:56 
ALT+F4 schließt das fokussierte Fenster sonst nix. Nur wenn das fokussierte Fenster so verdrahtet ist das damit auch das beenden der Anwendung zusammenhängt (Winforms macht das z.B. im Standardfall mit seiner Startform so) beendet das auch die Anwendung. Aber es gibt keinen direkten Zusammenhang zwischen Alt+F4 und dem beenden einer Anwendung.