devxlogo

Dynamically Creating Controls

Dynamically Creating Controls

Question:
I am a teacher (this explains my lack of expertise at understanding many VB technicalitiesin manuals etc.) experimenting with creating bits and pieces of software for children with learning disabilities and would like to know if there is an easy (novice easy!) way of doing this ….

  1. I want to type a letter on the keyboard, and I want VB to automatically create a button with that letter (label) on it on-screen.
  2. I want to type a letter on the keyboard, and I want VB to automatically create a similar button, but with pre-defined properties (perhaps already defined and ina dBase linked to VB).

Answer:
Here are the basic steps for this:

  1. Create a button on the screen, label it something like cbLetter or whatever.
  2. Set the index property of it to the number zero.
  3. Set the visible property to false.
  4. In the KeyPress event for the TextBox or wherever you are entering keys, to create a new button, you do: Set cbLetter(1) = New CommandButton That will create a new button at index #1. You then need to set the top, left, height and width properties, as well as the caption. There’s not really a good way to use a template or anything like that. You basically have to set the properties equal to those on another button, such as the invisible one. It’s not a particularly easy thing to do…it becomes a pain to manage.

See also  Comparing different methods of testing your Infrastructure-as-Code
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist