Question Massive Number of Custom Controls


New member
Dec 15, 2016
Programming Experience
What I'm trying to do is create an email template program that will walk an English second language user through creating an email using any number of set text blocks. Some of the text blocks have Blanks that the user will need to fill in and some of them won't.

Problem: There are somewhere in the neighborhood of 600-800 text blocks that need to have their own set of Label/Text controls to guide the user through depending on the situation. I'm not sure what the best way of handling this would be. The start of the program is a treeview control that lists out all of the available questions, then the text block complete with text, blanks, and instructions will appear.

the best idea I've come up with to create a custom control for each question and then add that control to the form using a sub from the treeview control.

Public sub Addcontrol()
dim thetemplate as new customcontrol
with thetemplate
.name = "thetemplate"
.location = new point(0, 0)
end with
end sub

the problem with this is that because the control was defined inside a sub I can't get access the properties and methods that go with the custom control.

I've found a couple places online that talk about using a RegisterName method to make the control available outside of the sub but I can't for the life of me figure out the syntax to make it work.

I can move the Dim statement to the outside of the sub but if I do that then I'll need to write a 1,000 or more subs instead of a couple to manage what i'm trying to do. so i'd prefer to avoid that if possible.

can anybody tell me how to make this work or if you have a better way to do that would be awesome as well?


VB.NET Forum Moderator
Staff member
Aug 17, 2004
Sydney, Australia
Programming Experience
The control is not "defined inside a sub". Your 'thetemplate' variable is declared inside that method so it's not accessible outside but that doesn't mean that the control you created and assigned to that variable isn't accessible. You added the control to the Controls collection of a GroupBox, so you can always access it there. Alternatively, you could make your method a Function and have it return the control it just created. As another alternative, you can assign the control to a member variable.
Top Bottom