Link to home
Start Free TrialLog in
Avatar of MKadric
MKadric

asked on

vb6 create image control (not picturebox) Dynamically

vb6 create image control (not picturebox) Dynamically

Must be a  control array.
    example
                     imgSi1(0), imgSi1(1) etc.

Create as many as needed at run time.

The example also must show how to place the image control array inside of another control at run time
         EXAMPLE place image control inside picturebox control

I already know how to creat command buttons, text box but I can not seem to get the image code to work and I do not know where to start to put the image control inside of a picturebox control.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

I don't believe you can dynamically create image controls the way you can create command buttons, textboxes, etc. You can however do this.

In the IDE, draw an Image control inside the picturebox and set the image control's Index property to 0 and set it's Visible property to False.

Then when you want to show the first one you of course just set it to Visible. To create others you do something like this


Load Image1(1)
Image1(1).Visible = True
Image1(1).Left = Image1(0).Left + 200
ASKER CERTIFIED SOLUTION
Avatar of eemit
eemit
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay you're right, but why do you say "You have to remove the controls added at run time"? Are you confusing that with the fact that when you use Load to create controls that you can only Unload those controls that you created at runtime?
'You also have to remove the controls added at run time using Load Method e.g. in Form_Unload
Private Sub Form_Unload(Cancel As Integer)
  Dim nItemCounter As Long
  For nItemCounter = Image1.UBound To 1 Step -1
      Unload Image1(nItemCounter)
  Next
End Sub

Open in new window

@Martin
it should read
You have to remove (destroy) controls created at Runtime e.g. in Form Unload:
You have to remove (destroy) controls created at Runtime e.g. in Form Unload:
Sorry, but that's not true.

Sorry, but that's not true.
Anyway, as a normal clean up.
>Set m_oImgSi1C(i) = Me.Controls.Add("VB.Image", "imgSi1C" & CStr(i), Me.Picture2)
It's been established as best practice to set all object instances to Nothing explicitly.
Anyway, as a normal clean up.
>Set m_oImgSi1C(i) = Me.Controls.Add("VB.Image", "imgSi1C" & CStr(i), Me.Picture2)
It's been established as best practice to set all object instances to Nothing explicitly.
That I can agree to but it can be done at any time and not just at EOJ (that's End Of Job in case I'm the only old timer here:) ).
Avatar of MKadric
MKadric

ASKER

I want to thank all for thier input... this has been a great help.