Results 1 to 8 of 8

Thread: New Problem (images from form1 to form2)

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    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

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    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 .

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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:
    1. Private imgNumber As Integer 'Declare this 1 just 1 time on top of the code (modular)
    2. 'inside each event
    3. Private Sub Command1_Click()
    4.     imgNumber = imgNumber + 1 'The variable holds the real position, reset to 0 to restart
    5.     Form2.Image1.Picture = Me.Controls("image" & CStr(imgNumber)).Picture
    6.     Form2.Show 'Show the other form with the image
    7. 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:
    1. Option Explicit
    2.  
    3. Private imgNumber As Integer
    4. Private Sub Command1_Click(Index As Integer)
    5.     imgNumber = imgNumber + 1
    6.     Form2.Image1.Picture = Me.Controls("image" & CStr(imgNumber)).Picture
    7.     Form2.Show 'Show the other form with the image
    8. 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:
    1. Private Sub Command1_Click(Index As Integer)
    2.     imgNumber = imgNumber + 1
    3.     Form2.Image1.Picture = Me.Image1.Index(imgNumber).Picture
    4.     Form2.Show 'Show the other form with the image
    5. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    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

  7. #7
    Member
    Join Date
    Feb 2006
    Posts
    48

    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:
    1. Private Sub Command1_Click(Index As Integer)
    2.     Form2.LoadNewImage (Index)
    3. End Sub

    And Form2 Code =
    VB Code:
    1. Public Sub LoadNewImage(ByVal Index As Integer)
    2.    
    3. Dim iCount As Integer
    4.    
    5.     iCount = Image1.Count
    6.     Load Image1(iCount)
    7.    
    8.     Image1(iCount).Top = Image1(iCount - 1).Top + Image1(iCount - 1).Height + 100
    9.     Image1(iCount).Left = Image1(iCount - 1).Left
    10.     Image1(iCount).Picture = Form1.Command1(Index).Picture
    11.     Image1(iCount).Visible = True
    12.  
    13. End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    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
  •  



Click Here to Expand Forum to Full Width