Results 1 to 9 of 9

Thread: Tracking mouse clicks within a group control

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Tracking mouse clicks within a group control

    Hey Guys,

    Glad to see some of the great minds are still here. I'm going to be frequenting this plethora of knowledge for the next couple of weeks as I attempt to complete my capstone software engineering class and finally get my undergrad. As usually I will typically need information or guidance. Since this is homework based. I have found my first issue. Allow me to digress....

    The task given to my team is to create a checkers game which will have the capability to pay either player vs player or player vs cpu. Before I can begin to work on logic I need to cross the hurdle of detecting mouse movement. I have created the board which consists of 64 panels inside a groupbox. Each panel will have 4 images layers on top with the .visible property set to false. I am familiar with mouse click events to a degree but apparently lack some of the know how required.

    Anyone know of any sources I can read referring to mouse clicks and how to track them? I'm pretty much trying to accomplish the following and don't know where to start. Mouse clicks aren't extensively covered in the documents/texts I have.

    On click event
    If mouse click is inside panel and mouse click is on checker image Then
    Next mouseclick sets checker.visible = true (on next panel)
    First checker.visible = false
    End If

    I could be way off here. I could be completely wrong uses just picturebox controls and may need to dive a lot deeper and create a checker piece class. I just don't know at this point.

    Just looking for some guidance from experienced individuals. Good to see you all again.

    Later.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Tracking mouse clicks within a group control

    To track the mouse you can use MouseMove event, MouseClick, MouseDoubleClick, MouseDown and MouseUp events (there are a couple of more exotic ones too).

    The signatures for all these events look like this:
    (ByVal sender As System.Object, ByVal e As System.MouseEvetnArgs)

    The e agrument have x and y properties that will hold the current mouse cursor coordinates and its Delta property will hold the information about mouse wheel.
    What else do you need?

    P.S. Why using 64 panels instead of 1 picturebox?
    Just draw everyting in one picturebox. It will be much easier than handling of 64 panels.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Tracking mouse clicks within a group control

    There are various ways to achieve your aim but I have to agree with cicatrix that there are far more efficient ways than what you describe. I'd suggest a single PictureBox containing a single Image of the playing board, then use GDI+ to draw the counters. Instead of having each square containing multiple PictureBoxes that you Show and Hide, just draw the Images of the counters wherever you need them and nowhere else. It will be far more efficient and not especially difficult. Follow the CodeBank link in my signature and check out my thread on manipulating GDI+ drawings. It's not exactly what you need but shows you how you can detect mouse events in various areas of the one control and how you can draw multiple "objects" onto a single control.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Tracking mouse clicks within a group control

    Alright,

    So summing up what I got here. You both think it would be easier to have a single picture box and use GDI interface to track where the mouse clicks are taking place? By doing so I would alleviate the problem of having to stack 2+ images on each panel and would instead just have to create the starting amount of 24 game pieces and manipulate their movement through GDI?

    Trust me I'm not doubting. I'm looking into it right now but in doing so wouldn't I have to set constraints that would reflect the positioning of each tile?
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  5. #5
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Tracking mouse clicks within a group control

    You should hold 2 image objects in memory - one for black and 1 for white pieces (or whatever colors you choose). Then you simply draw these images on the desired locations of the picturebox.

    (You'd better have a square picturebox, but a rectangular one will do also, but it will look weird). So I assume that Width = Height

    Dim sz As Double = PictureBox1.ClientRectangle.Width / 8

    Now, to place something at position 5,5 just multiply by this quotient

    Dim ActualPixelsX = 6 * sz
    Dim ActualPixelsY = 6 * sz
    ' Squares are indexed from zero: 0, 1, 2, 3, 4, 5, 6, 7 - that's why it's six, not five

  6. #6

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Tracking mouse clicks within a group control

    yeah John, I need to pick up on some of that. I think your right. Thats the way to go.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  7. #7

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Tracking mouse clicks within a group control

    Thanks Cicatrix,

    I'm starting to get a picture in my head here. I'm new to GDI
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  8. #8

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Tracking mouse clicks within a group control

    I mean new as in never used it before. I'm going to pick up some documentation, or a book.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  9. #9

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Tracking mouse clicks within a group control

    Ok you guys were definitely right. Single image, track mouse clicks through a click event to yield the X and Y cords. I can cross reference which tile on the board is being selected by dividing the X and Y both by 60, the size of a single playing tile, to determine where the piece needs to move.

    Now I need to load the arrays and test my logic muhahahaha!

    Thanks for the advice, and thanks for the how-to JM. Same to you Cicatrix!
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

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