kkoser
asked on
creating an image control.
I need to create a form (form2) that on dbl_Click of a listbox on (form1), it creates an image control and loads an image in the control on form2. As far as the movement and placement of the control, i can take care of that. It is kind of like Clicking on a Deck and having the Card put in your hand. i.e. i drew a Jack of Diamonds from the listbox, and the Jack goes into my hand.(Form2). This is very important to me so i will give more ponts if you want me too. Man...i have a lot to learn....:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private Sub Command1_Click()
If Image1(0).Visible = False Then
Image1(0).Visible = True
Else
Load Image1(Image1.Count)
Image1(Image1.ubound).Visi ble = True
Image1(Image1.ubound).Left = Image1(Image1.ubound).Left + 350
Image1(Image1.ubound).Top = 600
Image1(Image1.ubound).Pict ure = LoadPicture(Form1.ImagePat h)
End If
End Sub
thanx idle that did the trick. i was able to learn a little bit. i still need to learn more about arrays..like if i want to set the next images apart from each other i used this code. however it only moved one image over and the preceding images over the top...do you have any suggestions on how i might be able to line them up?
btw you got the points man thanx...i'll post it in a bit.
If Image1(0).Visible = False Then
Image1(0).Visible = True
Else
Load Image1(Image1.Count)
Image1(Image1.ubound).Visi
Image1(Image1.ubound).Left
Image1(Image1.ubound).Top = 600
Image1(Image1.ubound).Pict
End If
End Sub
thanx idle that did the trick. i was able to learn a little bit. i still need to learn more about arrays..like if i want to set the next images apart from each other i used this code. however it only moved one image over and the preceding images over the top...do you have any suggestions on how i might be able to line them up?
btw you got the points man thanx...i'll post it in a bit.
That probably would be better. For this to work acroos the two forms, your code on Form1 would need to look something like this:
Private Sub List1_DblClick()
With Form2
If .Image1(0).Visible = False Then
.Image1(0).Picture = LoadPicture("C:\MyPath\MyP icture.jpg ")
.Image1(0).Visible = True
Else
Load .Image1(Image1.Count)
.Image1(Image1.UBound).Pic ture = LoadPicture("C:\MyPath\MyP icture.jpg ")
.Image1(Image1.UBound).Vis ible = True
End If
End With
End Sub
If you are going to be controlling the Image objects programtically then you will need to keep track of what is being put in the Control array. Control object arrays are always numbering starting at zero, regardless of what Option Base yyou may have set for the Form. I don't know enough about the rest of your program to say what the best way for you to do this is, but one thing that might help would be for you to put identifying information in the Tag property when you create the new Image.
.Image1(Image1.UBound).Tag = "MyImgTag"
Then when the Image is clicked on Form2, you can find out what is being referred to as follows (this code would go in Form2):
Private Sub Image1_Click(Index As Integer)
Dim ImgName as String
ImgName = Image1(Index).Tag
End Sub
Idle_Mind, I tested the drag functions in your post and there are some strange behaviours, such as not being able to move a control up+left, controls cannot overlap unless they are being dragged from a certain directions, etc. Since kkoser said he can take care of the movement and placement of the control it probably doesn't matter too much; just FYI.
Private Sub List1_DblClick()
With Form2
If .Image1(0).Visible = False Then
.Image1(0).Picture = LoadPicture("C:\MyPath\MyP
.Image1(0).Visible = True
Else
Load .Image1(Image1.Count)
.Image1(Image1.UBound).Pic
.Image1(Image1.UBound).Vis
End If
End With
End Sub
If you are going to be controlling the Image objects programtically then you will need to keep track of what is being put in the Control array. Control object arrays are always numbering starting at zero, regardless of what Option Base yyou may have set for the Form. I don't know enough about the rest of your program to say what the best way for you to do this is, but one thing that might help would be for you to put identifying information in the Tag property when you create the new Image.
.Image1(Image1.UBound).Tag
Then when the Image is clicked on Form2, you can find out what is being referred to as follows (this code would go in Form2):
Private Sub Image1_Click(Index As Integer)
Dim ImgName as String
ImgName = Image1(Index).Tag
End Sub
Idle_Mind, I tested the drag functions in your post and there are some strange behaviours, such as not being able to move a control up+left, controls cannot overlap unless they are being dragged from a certain directions, etc. Since kkoser said he can take care of the movement and placement of the control it probably doesn't matter too much; just FYI.
lpzCoville,
The odd behaviour is because I only added code for the Form itself to accept a DragDrop. If you don't move the Image control enough to make the cursor leave it's own original boundary, then you are actually attempting to drop the control on itself, which isn't being trapped by the code.
kkoser,
This code in the button click would make the Image controls appear in a row, one after the next.
Private Sub Command1_Click()
If Image1(0).Visible = False Then
Image1(0).Visible = True
Else
Load Image1(Image1.Count)
Image1(Image1.ubound).Visi ble = True
Image1(Image1.ubound).Left = Image1(0).Left + Image1.ubound * Image1(0).Width
Image1(Image1.ubound).Top = Image1(0).Top
End If
End Sub
Idle_Mind
The odd behaviour is because I only added code for the Form itself to accept a DragDrop. If you don't move the Image control enough to make the cursor leave it's own original boundary, then you are actually attempting to drop the control on itself, which isn't being trapped by the code.
kkoser,
This code in the button click would make the Image controls appear in a row, one after the next.
Private Sub Command1_Click()
If Image1(0).Visible = False Then
Image1(0).Visible = True
Else
Load Image1(Image1.Count)
Image1(Image1.ubound).Visi
Image1(Image1.ubound).Left
Image1(Image1.ubound).Top = Image1(0).Top
End If
End Sub
Idle_Mind
ASKER
thanx...i put the control in the app. and can adjust it for when the number of controls get too big for the size of the form...kind of like fanning a deck of cards..it realy looks cool...thanx again.
ASKER
now to go back to the winsock control...man i am having a hard time with that...
https://www.experts-exchange.com/questions/20910092/trigger-events-using-winsock-db-and-images.html
https://www.experts-exchange.com/questions/20910092/trigger-events-using-winsock-db-and-images.html
Here is some code that will do the trick. If you want the user to be able to interact witht the image once you have create it, then you have to put the WithEvents statement in; otherwise you can leave it out. the variable "objMyImage" is used to reference the new Image control object you have created. You should jhave that in place before you call the Controls.Add method.
Option Explicit
' declare the reference variable for the Image control you are going to create
Private WithEvents objMyImage As Image
Private Sub List1_DblClick()
Form2.Visible = True
' add a new Image control on Form2
Set objMyImage = Form2.Controls.Add("VB.Ima
' set some basic properties for the new Image control
With objMyImage
.Picture = LoadPicture("C:\MyPath\MyP
.Visible = True
End With
End Sub
'here is an example of how you can use the event handler
Private Sub objMyImage_Click()
MsgBox "This is a dynamically added image."
End Sub
Depending on how your project is structured, you probably aren't going to want the reference variable for your dynamically created image control declared as Private within the Form1 code, as is the case in the example above; but this should get you started.