|
-
Mar 14th, 2006, 04:39 PM
#1
Thread Starter
New Member
New Problem (images from form1 to form2)
i use to have one command button and an image in form1
when i click that button the image appare in form2
that was a problem, it been solved by HACK
now
i have about 30 buttons with the same number of images (for every button an image)...in form1
how can i show image2 (when i click the command button 2[form1]) in the place of image1 in form2
and the next click i.e. : command button 10 in form 1 , i need it in the place of image2 in form2.......and so on
any help please
Thanks
Yours
HallaM
-
Mar 14th, 2006, 04:53 PM
#2
Re: New Problem (images from form1 to form2)
post the code u are using to put the image into form2
I would create a control array of command buttons and pictureboxes on form one...
So u have
Command1(0)
Command1(1)
Command1(2)
etc...
and
Picture1(0)
Picture1(1)
Picture1(2)
etc..
then for the code it should be easy
Private SUb Command1_Click(Index as integer)
Form2.Image1.Picture = Me.Picture1(Index).Picture
End Sub
(or something like that )
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 14th, 2006, 06:13 PM
#3
Thread Starter
New Member
Re: New Problem (images from form1 to form2)
this is the code for displaying the image in forme2(the code just for 3 command buttons):
'code in form1
Private Sub Command1_Click()
Form2.Image1.Picture = Image1.Picture
End Sub
Private Sub Command2_Click()
Form2.Image2.Picture = Image2.Picture
End Sub
Private Sub Command3_Click()
Form2.Image3.Picture = Image3.Picture
End Sub
etc..
(note: there is no code in form2,there is only the empty image frames on the form showing in design time )
now...
i need a way to display these images in order
i.e.:
if i click button 2(image2), i need it to be display in the empty image1 in form2
and if i click button5(image5) , i need it to be display in the empty image2 in form2
and so on
if it is not clear i will try to upload the whole project .
-
Mar 14th, 2006, 07:39 PM
#4
Re: New Problem (images from form1 to form2)
The best idea is what Static recommended, the best about using an array of buttons, is that you can use only 1 event, you dont need to create 30 events in code for each button , just 1.
Anyway, without control arrays, you should do this inside every button click event
VB Code:
Private imgNumber As Integer 'Declare this 1 just 1 time on top of the code (modular)
'inside each event
Private Sub Command1_Click()
imgNumber = imgNumber + 1 'The variable holds the real position, reset to 0 to restart
Form2.Image1.Picture = Me.Controls("image" & CStr(imgNumber)).Picture
Form2.Show 'Show the other form with the image
End Sub
Now if you create an array of 30 buttons, using that same code, you can handle your 30 buttons with only 1 event:
VB Code:
Option Explicit
Private imgNumber As Integer
Private Sub Command1_Click(Index As Integer)
imgNumber = imgNumber + 1
Form2.Image1.Picture = Me.Controls("image" & CStr(imgNumber)).Picture
Form2.Show 'Show the other form with the image
End Sub
It would be even better do create another array for the images, so you don't need to use Controls(), that's ugly, you can just reference them by index, like this:
VB Code:
Private Sub Command1_Click(Index As Integer)
imgNumber = imgNumber + 1
Form2.Image1.Picture = Me.Image1.Index(imgNumber).Picture
Form2.Show 'Show the other form with the image
End Sub
-
Mar 15th, 2006, 10:05 AM
#5
Thread Starter
New Member
Re: New Problem (images from form1 to form2)
Thanks all for the replys
but i do not think arrays will solve the problem
because i need it to be 30 button visiable(for the user GUI )
and the problem i have now that the image will appare depanding on its no. in form1
and also if i need to use the same image again the place of it is gone
what i need is:
when i click any button of the 30 i have in form1
the image of it will have the name of image1 in form2 (to be the first in form2)
and even if i click the same button again it will carry the name of image2 (to be beside image 1 in form2)
and so on
any ideas
Thanks
-
Mar 16th, 2006, 05:15 AM
#6
Thread Starter
New Member
Re: New Problem (images from form1 to form2)
ok here is how i need the vb programe to think :
'every button related to an image placed on form1
when the user click a button (in form1)
something need to go and look for the name of the last image (in form2)
if no image there, name it image1 and it will be placed in form2
'the user do nothing, nothing will change
the user click another button (it could be the same button )(all the buttons in form1)
somthing need to go to take a look if there is any images in form2
yes, we have one .
what is the name of it
image1
ok.
now this image willbe named image2
and will be placed in form2
'the user do nothing, nothing will change
and so on
some help
any ideas please
Thanks
-
Mar 16th, 2006, 06:25 AM
#7
Member
Re: New Problem (images from form1 to form2)
Ok, try this:
Make a project with 2 forms, form1 and form2.
On Form1 you have all your buttons in a control array so that you have Command1(0) to Command1(29)
Set all your images to all your Command1().Picture properties (either at design time manually or at runtime with automation).
On form2 you have 1 image in a crontrol array, Image1(0)
Now
Form1 code=
VB Code:
Private Sub Command1_Click(Index As Integer)
Form2.LoadNewImage (Index)
End Sub
And Form2 Code =
VB Code:
Public Sub LoadNewImage(ByVal Index As Integer)
Dim iCount As Integer
iCount = Image1.Count
Load Image1(iCount)
Image1(iCount).Top = Image1(iCount - 1).Top + Image1(iCount - 1).Height + 100
Image1(iCount).Left = Image1(iCount - 1).Left
Image1(iCount).Picture = Form1.Command1(Index).Picture
Image1(iCount).Visible = True
End Sub
-
Mar 17th, 2006, 04:31 PM
#8
Thread Starter
New Member
Re: New Problem (images from form1 to form2)
Well done ProMac Thanks for your help
but
for the final step of adding some lines of code in form2 (to move the image by the mouse ) i faced a big error message .
can any1 please help me to place the folloing code in form2 :
or any other code to move the image by mouse in the run-time .
Dim moveMe As Boolean
Private Sub image1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
moveMe = True
End Sub
Private Sub image1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If moveMe Then
Image1.Top = Image1.Top + Y
Image1.Left = Image1.Left + X
End If
End Sub
Private Sub image1_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
moveMe = False
End Sub
---------
'form2 code
Public Sub LoadNewImage(ByVal index As Integer)
Dim iCount As Integer
iCount = Image1.Count
Load Image1(iCount)
'Image1(iCount).Move = 1
Image1(iCount).Top = Image1(iCount - 1).Top
Image1(iCount).Left = Image1(iCount - 1).Left + Image1(iCount - 1).Width
Image1(iCount).Picture = Form1.Command1(index).Picture
Image1(iCount).Visible = True
End Sub
Thanks in advance
HallaM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|