Benutzer mit den meisten Antworten
Control auf Form erzeugen im Code

Frage
-
Hi,
will gerne wissen wie ich ein Control auf meiner Form erzeugt bekomme.
pb[i] = new PictureBox(); pb[i].Left = 400; pb[i].Top = 10; pb[i].Width = 20; pb[i].Height = 20; this.Controls.Add(pb[i]);
Mit Controls.Add funktioniert es leider nicht.
Sollte es ja eigentlich, aber tut es leider nicht.
Antworten
-
Hallo,
pb[i] = new PictureBox(); pb[i].Left = 400; pb[i].Top = 10; pb[i].Width = 20; pb[i].Height = 20; this.Controls.Add(pb[i]);
Mit Controls.Add funktioniert es leider nicht.
schaut nicht verkehrt aus. Kann es sein, dass Du die PictureBox nicht siehst, weil sie die gleiche Hintergrundfarbe hat, wie das Formular (Standard Schaltflächenfarbe). Probier mal zusätzlich:
pb[i].BackColor = Color.Red;
IMO wird Dein Code übersichtlicher, wenn Du mit Size und Location arbeitest:
pb[i].Size = new Size(20, 20); pb[i].Location = new Point(400, 10);
Aber das hat nichts damit zu tun, dass Du die hinzugefügte PictureBox nicht siehst.
Thorsten Dörfler
Microsoft MVP Visual Basic
vb-faq.de- Als Antwort markiert Robert Breitenhofer Freitag, 14. Januar 2011 18:33
-
Hallo alle zusammen,
Versuch es dochmal mit:
System.Windows.Forms.PictureBox PB = new System.Windows.Forms.PictureBox(); PB.Size = new System.Drawing.Size(20, 22); PB.Location = new System.Drawing.Point(400, 10);
Ich hoffe ich habe die Frage richtig Verstanden
Wenn man sie nun noch nicht sieht, dann folgende Zeile hinzufügen:
PB.Show();
- Als Antwort markiert Robert Breitenhofer Freitag, 14. Januar 2011 18:33
Alle Antworten
-
Hallo,
pb[i] = new PictureBox(); pb[i].Left = 400; pb[i].Top = 10; pb[i].Width = 20; pb[i].Height = 20; this.Controls.Add(pb[i]);
Mit Controls.Add funktioniert es leider nicht.
schaut nicht verkehrt aus. Kann es sein, dass Du die PictureBox nicht siehst, weil sie die gleiche Hintergrundfarbe hat, wie das Formular (Standard Schaltflächenfarbe). Probier mal zusätzlich:
pb[i].BackColor = Color.Red;
IMO wird Dein Code übersichtlicher, wenn Du mit Size und Location arbeitest:
pb[i].Size = new Size(20, 20); pb[i].Location = new Point(400, 10);
Aber das hat nichts damit zu tun, dass Du die hinzugefügte PictureBox nicht siehst.
Thorsten Dörfler
Microsoft MVP Visual Basic
vb-faq.de- Als Antwort markiert Robert Breitenhofer Freitag, 14. Januar 2011 18:33
-
Hallo alle zusammen,
Versuch es dochmal mit:
System.Windows.Forms.PictureBox PB = new System.Windows.Forms.PictureBox(); PB.Size = new System.Drawing.Size(20, 22); PB.Location = new System.Drawing.Point(400, 10);
Ich hoffe ich habe die Frage richtig Verstanden
Wenn man sie nun noch nicht sieht, dann folgende Zeile hinzufügen:
PB.Show();
- Als Antwort markiert Robert Breitenhofer Freitag, 14. Januar 2011 18:33