Hallöle liebe Community und Christian,
vorhin wollte ich meine MainForm etwas auslagern das ich nicht so viel Code in der Form.cs und im Form.Designer.cs habe, jedoch stoß ich auf einen, ich hoffe, klitzekleinen Fehler...
Ich habe in meiner MainForm, eine Listbox in einem Splitcontainer der sich im 2. Panel befindet. Nun hab ich eine eigene Klasse geschrieben, in der ich eine eigene Listbox definiere und von der ListBox-Klasse ableite. Füge ich dieses Control nun dem Splitcontainer hinzu, werden die Eigenschaften an der ListBox nicht übernommen, Eventhandler funktionieren auch nicht.
Kann mir evtl. jemand helfen?
Hier der Code:
Attribute in der FormKlasse
C#-Quelltext
1:
| private ACListBox playListBox; |
Instanziierung in dem Standardkonstruktor
C#-Quelltext
1: 2:
| this.playListBox = new ACListBox(); this.formSplitContainer.Panel2.Controls.Add(this.playListBox); |
Die eigens erstellte ListBoxKlasse
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: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
| class ACListBox : ListBox {
#region Attributes
private ListBox acListBox; private String pTrackName;
public String trackName { get { return this.pTrackName; } set { this.pTrackName = value; } }
#endregion
public ACListBox() { this.acListBox = new ListBox(); this.acListBox.Dock = System.Windows.Forms.DockStyle.Fill; this.acListBox.FormattingEnabled = true; this.acListBox.Location = new System.Drawing.Point(0, 0); this.acListBox.Name = "playListBox"; this.acListBox.Size = new System.Drawing.Size(248, 420); this.acListBox.TabIndex = 0; this.acListBox.Click += new EventHandler(acListBox_Click); } public ACListBox(ListBox listBox) { this.acListBox = listBox; }
public void getItem() { this.acListBox.Items.Add(this.trackName); }
private void acListBox_Click(object sender, EventArgs e) { MessageBox.Show("Blubb"); } } |