views:

1560

answers:

4

I'm attempting to create a Wizard type control in VB6 and have run into a stumbling block.

I'd like to allow users of the control to be able to add and manage CWizardPage(s) to the design time control using a property page.

The first approach I used was to add the Wizard pages to the OCX directly using a Collection, however I ran into two problems in that the Collection class is not persistable (and I couldn't find an easy way to make it so) and that VB6 seems very limited in it's ability to instantiate controls at run time - so it would seem to be a struggle to actually re-instantiate them.

My next thought was to just allow the users to draw the wizard pages at design time. This sort of works, however it's far too easy to draw one of the wizard pages inside another wizard page instead of inside the CWizardContainer.

So can anyone please tell me how to add controls to a form at design time without using drag 'n' drop?

+1  A: 
Mike Spross
A: 

...VB6 seems very limited in it's ability to instantiate controls at run time...

Nothing could be further from the truth. Instantiating controls at run time in VB6 is trivial.

  1. At design time, set the Index property of the control to 0. This turns the control into a control array.
  2. At runtime, load new instances of the control as needed.

As an example, create new Standard EXE project drop a TextBox onto the form, set its Index to 0 and put the following in the Form_Load event:

Private Sub Form_Load()

    Dim newIndex As Integer

    newIndex = Text1.UBound + 1
    Load Text1(newIndex)
    Text1(newIndex).Top = Text1(newIndex - 1).Top + Text1(newIndex - 1).Height
    Text1(newIndex).Visible = True

End Sub
raven
A: 

I have worked on an application that regularly made many whole data entry screens dynamically based on the desired fields. It's verbose to specify the Top, Left, Width, and Height all the time. So, you usually have a "template" of the control and copy those settings to the additional one.

ssorrrell
A: 

The code given by raven above is good if we use it for vb inbuilt controls... but if I want to use my own UserControl dynamically and I want to display it in another tab of SSTab control or on a frame I can't get it to work because the .Container is not available for UserControl.... Any help??????

anonymous
If you have a follow-up question you should better ask it as a new question, not post it as an answer. More people would see it that way and would try to answer. The "Ask Question" button is in the top right of the page.
sth