CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Posts
    44

    i need ideas in...

    well, i had loaded array of images during run-time and when the user clicks on the imagebox then the image is shown and when the user clicks on the other imagebox then the other image also shown.

    well my problem is that, how can i compare the image which is first clicked with the image which is second clicked?

    if both pics are of the same then both pics will remain in the imagebox (means shown), else both pics is closed (means unload picture).

    private Sub imagebox_Click(Index as Integer)
    :
    :
    :







  2. #2
    Join Date
    Mar 2001
    Posts
    44

    Re: i need ideas in...

    i am doing it in this way, but does not worked out well, can someone help me?

    i am comparing the filename instead see below:
    if both filename are same then i load the 2 similar pics
    else if the two filename are not the same then i unload the 2 pics.


    private Sub imgbox_Click(Index as Integer)
    Dim filepath as string
    Dim tem1 as string, tem2 as string
    Dim num1 as Integer, num2 as Integer
    static j%

    filepath = "C:\Unzipped Files\pics\Icons" & "\im" & imgControl(Index).Tag & ".ico"
    imgControl(Index).Picture = LoadPicture(filepath)

    j% = j% + 1
    If j = 1 then 'first click on one pic..
    tem1$ = filepath 'store filename to here...
    num1 = Index 'store index to a number

    End If

    If j = 2 then 'second click on the other pic....
    tem2$ = filepath 'store filename here...
    num2 = Index
    End If

    If tem1$ = tem2$ then 'when 2 filenames are same

    imgControl(num1).Picture = LoadPicture(tem1) 'load pics when they are of the same
    imgControl(num2).Picture = LoadPicture(tem2)
    else 'when not the same then clear the two pics
    imgControl(num1).Picture = LoadPicture()
    imgControl(num2).Picture = LoadPicture()
    End If

    If j% > 3 then 'reset counter
    j% = 0
    End If



    does anyone know how to solve this?



  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: i need ideas in...

    Try this one:


    ' NOTE: assumption here is that your image control
    ' index starts from 1 instead of 0
    private Sub imgControl_Click(Index as Integer)
    static nLastIndex as Integer ' stores the last clicked imgControl

    ' load picture and save PATH into the .TAG of control
    dim szPicPath as string
    szPicPath = "C:\Unzipped Files\pics\Icons" & "\im" & imgControl(Index).Tag & ".ico"
    set imgControl(Index).Picture = LoadPicture(szPicPath)
    imgControl(Index).Tag = szPicPath ' save it

    ' check if last index > 0
    if (nLastIndex > 0) then
    ' this is a second click - check if it is the same imgControl
    if (nLastIndex = Index) then ' nothng to do so exit
    exit sub
    end if

    '
    ' compare path
    if (ucase(imgControl(nLastIndex).Tag) <> ucase(imgControl(Index).Tag)) then
    ' clear image on both image control
    set imgControl(nLastIndex).Picture = nothing
    set imgControl(Index).Picture = nothing
    end if

    '
    ' reset the last index
    nLastIndex = 0
    else
    ' save this index
    nLastIndex = Index
    end if
    End Sub




    Have not really tested that code, email me if you still having problems with it:

    -Cool Bizs

    Good Luck,
    -Cool Bizs

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

Featured