Question how can i declare the maxinum number for creating richtextbox?


Active member
Feb 23, 2014
Programming Experience
plss help..
this is my code
RichTextBox rich = new RichTextBox { Parent = tab, Dock = DockStyle.Fill, Name = "richbox" + f++, Enabled = false };

how can i put limitation for making rtb? i put a name for it but nothings happen.
when i used the richbox i always got a error. name does'nt exist.

i dont know what i gonna do :( pls help..!


C# Forum Moderator
Staff member
Apr 23, 2011
Sydney, Australia
Programming Experience
You are under some misconceptions. The Name property of the RichTextBox is just a property like any other. It doesn't magically make the form have a member variable with the same name. When you add a control in the designer and set its Name, the designer automatically declares a member variable with the same name and it's that variable that you use to access the control. If you create the control at run time then there's no such member variable, obviously. You need to use another approach to access the control. If you do set its Name then you can use that name to index the parent's Controls collection. Alternatively, and preferably, you would create your own collection and access the controls by index.
Top Bottom