Results 1 to 7 of 7

Thread: Detecting which card was clicked with cards.dll?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Detecting which card was clicked with cards.dll?

    Does anyone have any idea how I can detect which card the user clicked on a card game when using cards.dll?

    I cannot figure out how because it is not an actual object on the form but is drawn with the OnPaint event.


    http://www.vbforums.com/showthread.p...46#post2417446

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Detecting which card was clicked with cards.dll?

    i dunno what you're doing. But if you have cards drawn on the form and you want to figure out which is clicked, then you need to put some code in the Form's click event. Then you can do hit testing. You can check the mouse coordinates of the click and see if those coordinates fall inside a certain card or not.
    To make it easier you can declare a Region (System.Drawing.Region) variable for each card you have. You can define the cards' regions in each variable, and on the form_click event you can call each region's IsVisible (float x, float y) method using the clicked mouse coordinates.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Re: Detecting which card was clicked with cards.dll?

    Thanks for the help.

    I am trying to write a card game.
    The problem is some cards over lap eachother and some you need to drag so im not exactly sure on how to do that but Im still thinking. I figured thats what I would have to do but seems like a bunch to keep track of. I was just wondering if there was an easier way.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Detecting which card was clicked with cards.dll?

    Just create a rectangle for each of the cards you draw, then test the mouse coordinates against each rectangle (most recently drawn card's rect first, and then the second most recent and so on) until you find one that the mouse clicked inside, thats the card that got clicked on.
    I don't live here any more.

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Detecting which card was clicked with cards.dll?

    same thing wossy!! shame on you
    regions are better
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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

    Re: Detecting which card was clicked with cards.dll?

    I would use an structure with a rectangle, this structure should contain more variables also. You can use Contains method of the rectangle, it returns True when the X,Y coordinates passed are inside.
    I use regions when the figure is going to be transformed (scaled/rotated..), else a rectangle should be enough.
    Last edited by jcis; Apr 2nd, 2006 at 09:52 PM.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Detecting which card was clicked with cards.dll?

    As an alternative approach, you could make the cards a custom control, which would take care of the hit testing for you.

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