Autor Beitrag
qwertzqwertyqwertzqwerty
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
C# VS 2008
BeitragVerfasst: Di 05.08.08 14:07 
Ich wollte ein Programm schreiben, dass z. B. beim Drücken der Enter Taste den Inhalt einer PictureBox ändert. Habe im Galileo OpenBook nachgeschlagen und folgenden Code geschrieben, der aber leider nicht Funktioniert:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode == Keys.Enter)
            {
                MessageBox.Show("Es wurde die Enter-Taste gedrückt");
    pictureBox1.Image = WindowsFormsApplication.Resource1.bla;
                e.Handled = true;
            }
        }
    }
}


Er löst aus irgendeinem Grund das Ereignis nicht aus :nixweiss:
Form1.KeyPreview hab ich auf true gesetzt.
Kann mir jemand meinen Fehler sagen?


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Di 05.08.2008 um 14:09
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 05.08.08 14:11 
Blöde Frage: Du hast die Methode aber auch dem entsprechenden Ereignis der Form zugeordnet, oder?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
qwertzqwertyqwertzqwerty Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
C# VS 2008
BeitragVerfasst: Di 05.08.08 19:05 
Äh, wie mach ich das?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 05.08.08 19:16 
Im Formdesigner kannst Du Dir nicht nur die Eigenschaften eines Objektes anzeigen lassen, sondern auch die Ereignisse eines Objektes. In der Eigenschaften-Box dafür mal auf das Blitz-Symbol klicken. Jedem Ereignis kannst Du dann eine Methode zuordnen (per Doppelklick neu anlegen oder per Einfach-Klick existierende auswähle <- das willst Du).

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
qwertzqwertyqwertzqwerty Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21

Win XP
C# VS 2008
BeitragVerfasst: Di 05.08.08 19:25 
Danke, es funktioniert :dance2: