Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Form Via Code and Save

Status
Not open for further replies.

Trob70

Programmer
Sep 25, 2012
89
AU


I have created a new project and created a new form Form1 on which i need a LARGE number of controls

I am trying to avoid having to manually add all the controls !!!!

Using code i have generated all the controls and the form loads and works fine

eg...
'add a textbox
Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
1, 2500, 100
ctlText.BackColor = vbYellow

----

BUT

How do i SAVE the form with the detail i have generated for future use

Appreciate any help

Regards Trob

 
Salty,
Thanks for your replay.
I have had a good look and it appears it is not possible to do this in vb6
Not going to worry about it, i have done it manually

Many Thanks


Trob
 
>it is not possible to do this in vb6

It is, you know. Although you need to do it via VB6 IDE Extensibility - i.e an AddIn.

And then it's is pretty much as simple as (this is not complete code!):

Code:
[COLOR=blue] 
    Dim myform As VBComponent
    Dim MyControl As VBControl

    Set myform = VBInstance.ActiveVBProject.VBComponents.Add(vbext_ct_VBForm)
    Set MyControl = myform.Designer.VBControls.Add("Textbox", Nothing)

    MyControl.ControlObject.Move 100, 100, 600, 400
    MyControl.ControlObject.BackColor = vbYellow
    myform.SaveAs "C:\downloads\EXAMPLE2.FRM"[/color]
 
Trob said:
i need a LARGE number of controls

Did you consider a different approach? Like, instead of 100's of text boxes, use a Grid?
Instead of a lot of Option Buttons, use a drop-down list, etc...

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top