how can i create a textbox with a set position and size on a form at runtime?
thanks,
marvin
Printable View
how can i create a textbox with a set position and size on a form at runtime?
thanks,
marvin
Very easy. It should be something like this:
VB Code:
Dim mytextbox as New TextBox mytextbox.Size=New System.Drawing.Size(80, 16) mytextbox.Location = New System.Drawing.Point(184, 4) ....' any other property goes here. [b]dont forget[/b] to add this textbox to form or whatever container you need. Form1.Controls.Add(mytextbox)
Out of curiosity, what is the advantage of creating controls at runtime?
From what i have learned from gurus here, i can say when you know what you are doing and it's planned , its better to add them at desgin time.
But isn't it a lot more work to add them all like that instead of just slapping them on the form? And wouldn't that slow down your program if you had like a thousand controls to load?
Yes, more work, and more chance of run time errors.Quote:
Originally posted by The Phoenix
But isn't it a lot more work to add them all like that instead of just slapping them on the form? And wouldn't that slow down your program if you had like a thousand controls to load?
Usually , people do that they should have the Runtime Controls Manager part done (or whatever they call it) . This manager handles everything for runtime created controls from naming or setting some properties to the diffictult part which controlling events . I've seen one manager but I can't remember where . It's jut huge and it scared me really . Like 4 classes and I believe the possiblity of araisng errers is just zero . Most often , you need that when your app has a lot of controls while it's running , it eats up more memory and sends you an error message saying 'Out of Memory' . So , you tends to build that at runtime . Plus the exe would be farily smaller and faster .
Ah. Thank you for the explanation Pirate.