Results 1 to 21 of 21

Thread: picture box data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    picture box data

    hi is there a way i can find out if pic1.Image has been dropped onto another picture box. thanks

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: picture box data

    If pic1.Image = pic2.Image Then
    'Same picture
    Else
    'Not same Picture
    End If

    ??
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    Are you asking whether you can test whether two picture boxes contain the same image or are you asking how to perform a drag-and-drop operation between two picture boxes?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    thats good but i have 9 picture boxes to compare. is there one statement where i can check if its true. i'm using drag and drop funtionality

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: picture box data

    Quote Originally Posted by Prav
    thats good but i have 9 picture boxes to compare. is there one statement where i can check if its true. i'm using drag and drop funtionality
    If you have 9 boxes then use a loop. There is no method in the .Net framework tailored for every situation; you'll have to write it yourself.

    So are you say you're trying to compare 9 picture boxes... but you are also uses drag and drop. As jmcilhinney said, are you trying to just compare images or trying to drag and drop images?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    its for a noughts and crosses (tic tac tac) game. my problem i'm having is if you drag and drop a nought( for example) onto an empty space on the form or outside , i.e not on the 9 picture boxes, it still counts it as a turn meaning you can drag and drop a cross.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    You should be handling the DragDrop event of the picture boxes to know whether the image was dropped on one of them. If it was then it counts as a turn, otherwise it doesn't.

    Having said that, most people would just click a square to make a move in that square rather than using drag-and-drop. If this is an exercise to learn how to drag-and-drop then by all means carry on. Otherwise, Id' go with the other method as it's a more intuitive way to play the game in my opinion.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    The drapDrop is working ok. Can i have some help how to implement that handling DragDrop event to know whether the image was dropped on any picture boxes.

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    You should be handling of DragDrop event of the picture boxes. If the event is raised by a picture box then the image was dropped on that picture box. No drop = no event = no drop.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    how will i know there's no event

    VB Code:
    1. Private Sub picCrosses_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picCrosses.DragDrop
    2.         If pic11.Image Is picCrosses.Image Or pic12.Image Is picCrosses.Image Or pic13.Image Is picCrosses.Image Or _
    3.                         pic21.Image Is picCrosses.Image Or pic22.Image Is picCrosses.Image Or pic23.Image Is picCrosses.Image Or _
    4.                         pic31.Image Is picCrosses.Image Or pic32.Image Is picCrosses.Image Or pic33.Image Is picCrosses.Image Then
    5.         Else
    6.             MessageBox.Show("Please choose an empty box")
    7.             OX = False
    8.         End If
    9.     End Sub

  11. #11
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: picture box data

    Was that supposes to be: "How will I know, because there is no event," or "How will I know that there is no event?"

    You have the following events at your disposal: DragDrop, DrapEnter, DragLeave and DragOver.

    You can code events for each control or for multiple controls at once. To do more than one try something like this:
    VB Code:
    1. Private Sub PictureBoxHandler_DragDrop( _
    2.                 ByVal sender As Object, _
    3.                 ByVal e As System.Windows.Forms.DragEventArgs) _
    4.             Handles PictureBox1.DragDrop, PictureBox2.DragDrop, PictureBox3.DragDrop, _
    5.             PictureBox4.DragDrop, PictureBox5.DragDrop
    6.         ' Do something here
    7.     End Sub

    This will cause all of the picture boxes to call the same event handling procudure when the event is raised. Then sender will hold the picturebox that did the calling.
    Last edited by eyeRmonkey; Apr 13th, 2006 at 11:46 PM.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    The whole point is that you don't need to know if there was no drop event. You shouldn't do anything until there is a drop event, so if one isn't raised then nothing is done. Don't record a move when the user starts dragging. When the drop event is raised, then you should record that a move has been made. If the drop never occurs then there is nothing to undo because nothing was done.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    is there any website you would recomend so i can get the functionality of DragDrop, DrapEnter, DragLeave and DragOver

  14. #14
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    There's this web site called MSDN. You may have heard of it.

  15. #15
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: picture box data

    Quote Originally Posted by jmcilhinney
    There's this web site called MSDN. You may have heard of it.




    </SarcasmOn>Also, these two cool guys made this awesome search engine called Google.</SarcasmOff>
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    basically what i'm asking is how can i get the 'data' of where the picture has been dropped

  17. #17
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    You handle the DragDrop event of each PictureBox. When the event is raised the 'sender' argument is a reference to the PictureBox that the image was dropped on and the 'e' argument contains data about the event, like the coordinates of the drop location, etc. The following link is a drag and drop howto. It is not for images but you just have to experiment a little. I implemented drag-and-drop myself for the first time about a week ago. I just read the help documentation for all the events and type sinvolved and experimented a bit.

    http://support.microsoft.com/default...b;en-us;306969

  18. #18
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: picture box data

    Quote Originally Posted by prav
    basically what i'm asking is how can i get the 'data' of where the picture has been dropped
    We have answered that question many times. It is clear that you understanding of the structure of events is lacking, but alas, that is why you came here.

    Let's try this again.

    An event will be raised when something happens. The DragDrop event will occur when the user drops something onto that picture box. So if you want to do something when that happens, put code in the event handler:
    VB Code:
    1. Private Sub PictureBoxHandler_DragDrop( _
    2.                 ByVal sender As Object, _
    3.                 ByVal e As System.Windows.Forms.DragEventArgs) _
    4.             Handles PictureBox1.DragDrop, PictureBox2.DragDrop, PictureBox3.DragDrop, _
    5.             PictureBox4.DragDrop, PictureBox5.DragDrop
    6.         ' This sub will be called when any of the 5 picture boxes have something
    7.         ' dropped onto them
    8.         ' the sender argument now holds WHICH picture box called the event
    9.         Debug.WriteLine(sender.Name) ' should print the name of the picturebox you dropped onto
    10.     End Sub

    On the drag leave event you could set the picture of the SENDER to a module level variable (declared at the top of your form code - inside the class of course). Then when a DragDrop occurs, you could use the picture stored in that variable and set it to the SENDER's .Image property. There might be a better way, but that is what came to mind for me.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  19. #19
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: picture box data

    Quote Originally Posted by eyeRmonkey
    There might be a better way, but that is what came to mind for me.
    In the DragStart event handler you set the e.Data property to the data that is being dragged. In the DragDrop event you retrieve that same data from the e.Data property.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Re: picture box data

    thank you very much eyeRmonkey. i'll give that a go.

  21. #21
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: picture box data

    Quote Originally Posted by jmcilhinney
    In the DragStart event handler you set the e.Data property to the data that is being dragged. In the DragDrop event you retrieve that same data from the e.Data property.
    Cool. I knew there was something better, I just haven't done any DragDrop stuff in .NET yet.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

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