Results 1 to 3 of 3

Thread: Massive Number of Custom Controls

  1. #1
    Mandragoran is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    2
    Reputation
    0

    Massive Number of Custom Controls

    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
    mastergroupbox.cotnrols.add(thetemplate)
    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?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,776
    Reputation
    1703
    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.

  3. #3
    Mandragoran is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2016
    Posts
    2
    Reputation
    0
    Thanks for the help I was able to access the control through the groupbox controls collection.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •