|
Hello, I have a user control that contains a TextBox in it. I want to be able to change the properties of the TextBox at design time. For the most part I got it to work, but there's a small problem. Here's the sample code:
public class MyUserControl : System.Windows.Forms.UserControl { ... ... [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public TextBox TBox { get { return this.textBox1; } } ... ... }
public class Form1 : Form { ... // // userControl11 // this.userControl11.Controls.Add(this.userControl11.TBox); // how can I prevent this? this.userControl11.Location = new System.Drawing.Point(64, 32); this.userControl11.Name = "userControl11"; this.userControl11.Size = new System.Drawing.Size(128, 32); this.userControl11.TabIndex = 0; // // userControl11.TBox // this.userControl11.TBox.Location = new System.Drawing.Point(0, 0); this.userControl11.TBox.Name = "textBox1"; this.userControl11.TBox.TabIndex = 0; this.userControl11.TBox.Tag = "asd"; this.userControl11.TBox.Text = "textBox1"; ... ... }
This is exactly what I want it to do, except for the part where it adds the TextBox to the Controls collection of UserControl again. Why does it do this, since the UserControl will add it itself? Any help appreciated. Thanks Amit
|