1

I found a code for my project I have due online for Visual Basic. When I paste the code into Visual Basic and click run, is there a way for Visual Basic to make the form for me? Or do I have to make the forms myself based on the code?

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
jas
  • 11
  • 1
  • Typically you'll see some methods that have `Handles XXX.YYY` on the end of them. The "XXX" part is the name of the control, while the "YYY" part is the the event that is being trapped. You can sometimes figure out what type of control it is based on the name and/or the event being used. Drop a control of that type on your form and then change the name so that it matches. – Idle_Mind Jun 17 '20 at 00:31
  • Are you asking is it possible to create a form at run time, or are you asking how to create a form via the form designer that matches some code you've downloaded? – Hursey Jun 17 '20 at 01:43

2 Answers2

0

You have to create the form yourself:

  1. Create a Form.
  2. Insert your existing code. Comment everything inside the class.
  3. Create the controls.
  4. Name your controls with the names your code needs.
  5. Un-comment the previously commented code.

Have fun.

laancelot
  • 3,138
  • 2
  • 14
  • 21
  • 2
    Commenting out the pasted code is not necessary. In fact, not doing so is a good idea because the compilation errors will show you want you still need to add to the form in the designer. – jmcilhinney Jun 17 '20 at 03:05
  • While you're essentially right, I would still advice to comment as VS sometimes plays tricks when we change names in the designer, especially if the programmer is fumbling his way around his work. For an experienced programmer who already knows what and how to do what he wants, your method would of course be best. – laancelot Jun 17 '20 at 11:52
0

You can create different controls inside your class by code only as you wish, but you must create your form first, unfortunately this must be done manually

GME
  • 156
  • 2
  • 2
  • 16