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

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
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..!
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,136
Location
Sydney, Australia
Programming Experience
10+
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.
 

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
can u give me and example? by using the richtextbox? what syntax will i used to do that?
 
Top Bottom