Autor Beitrag
John Sanson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72

WinXP,WinVista
Delphi(BDS2006, 5), C#(VS2005, BDS2006), VB6
BeitragVerfasst: Mo 14.05.07 17:54 
Hi,

ich habe ein Objekt(Control) welches ich erst zur Laufzeit dynamisch erstelle.

Wie kann ich nun auf die Ereignisse des Objekts zugreifen?

z.B KeyPress

Gruß Chris
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 14.05.07 22:55 
Ein Beispiel:
ausblenden C#-Quelltext
1:
wclient.UploadProgressChanged += new System.Net.UploadProgressChangedEventHandler(wclient_UploadProgressChanged);					

Das ist jetzt ein Event des WebClients.
Wenn du den Anfang tippst, etwa bis "+=", dann steigt Visual Studio 2005 gleich mit ein und schlägt den Rest von selbst vor.
wclient_UploadProgressChanged ist dann die Methode, die bei dem Ereignis ausgeführt wird.

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN
John Sanson Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72

WinXP,WinVista
Delphi(BDS2006, 5), C#(VS2005, BDS2006), VB6
BeitragVerfasst: Mo 14.05.07 23:26 
Ist es auch möglich immer das gleiche Event auf alle gleichen Controls anzuwenden z.B.

TextBox.Change += new System......?

Also das dieses Ereignis von alles Controls gleichen Typ aufgerufen wird.
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 15.05.07 07:06 
user profile iconJohn Sanson hat folgendes geschrieben:
Ist es auch möglich immer das gleiche Event auf alle gleichen Controls anzuwenden z.B.

TextBox.Change += new System......?

Also das dieses Ereignis von alles Controls gleichen Typ aufgerufen wird.

Klar, ist ja genauso in Delphi möglich ;)
John Sanson Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72

WinXP,WinVista
Delphi(BDS2006, 5), C#(VS2005, BDS2006), VB6
BeitragVerfasst: Di 15.05.07 21:09 
hmm es funktioniert nicht so wie es soll.

Hättest du etwas Beispielcode dazu?
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 16.05.07 08:44 
user profile iconJohn Sanson hat folgendes geschrieben:
hmm es funktioniert nicht so wie es soll.

Hättest du etwas Beispielcode dazu?

Was funktioniert nicht, wie äußert es sich und welchen Code hast Du dafür geschrieben? Du musst schon mehr Informationen geben.
John Sanson Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72

WinXP,WinVista
Delphi(BDS2006, 5), C#(VS2005, BDS2006), VB6
BeitragVerfasst: Mi 16.05.07 11:59 
Also wenn ich
ausblenden C#-Quelltext
1:
textBox1.TextChanged += new EventHandler(textBox1_TextChanged);					


ist ja alles ok.
Aber ich will ja ein Event für alle TextBox Objekte. Hab versucht

ausblenden C#-Quelltext
1:
TextBox.TextChanged += new EventHandler(textBox_TextChanged);					


aber von dort kann ich nicht aufs Event zugreifen.
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mi 16.05.07 12:17 
Aber so geht es doch:
ausblenden C#-Quelltext
1:
2:
TextBox1.TextChanged += new EventHandler(AllTextBoxes_TextChanged);
TextBox2.TextChanged += new EventHandler(AllTextBoxes_TextChanged);

Gruß Jürgen
John Sanson Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 72

WinXP,WinVista
Delphi(BDS2006, 5), C#(VS2005, BDS2006), VB6
BeitragVerfasst: Mi 16.05.07 12:27 
ja das stimmt. So hab ichs auch gestern Abend noch gemacht.
Dachte nur ich kann der Klasse direkt dieses Ereignis zuweisen, damit bei instanzierung das event sofort vorhanden ist.
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 16.05.07 12:34 
user profile iconJohn Sanson hat folgendes geschrieben:
ja das stimmt. So hab ichs auch gestern Abend noch gemacht.
Dachte nur ich kann der Klasse direkt dieses Ereignis zuweisen, damit bei instanzierung das event sofort vorhanden ist.

Nein, das geht so nicht. Aber Du könntest über das Controls-Property alle Controls durchgehen und die Textboxen entsprechend ändern:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
foreach (Control c in this.Controls)
{
  if (c.GetType() == typeof(TextBox))
    ((TextBox) c).TextChanged += new EventHandler(AllTextBoxes_TextChanged);
}

Der Code ist jetzt aus dem Kopf geschrieben, daher keine Gewähr, dass er so direkt funktioniert ;)