0

So I'm making a game (specifically Hearthstone) for my Programming II class because I have no better ideas. During my attempt, I realize that creating the Card interface would be much harder than I thought. The Card interface extends the PictureBox class like this:

Card : System.Windows.Form.PictureBox

Now, what I want to do is create an event for when the mouse clicks and releases the PictureBox. I know that the way to create the event requires the object sender and EventArgs e, but I'm not sure how to make it handle the actual event. For example, when I write the code

static void Play(object sender, EventArgs e){}

I wish to have it handle the PictureBox's OnMouseUp event, but I have no idea what object to say it handles. I searched it up, but either I was using the wrong keywords and not finding the right thing or it hasn't been a post yet. Here's what I have now, and I'm not sure if it works; I haven't really gone around to testing it because I'm not in a computerized area this winter break:

static void Play(object sender, EventArgs e) handles Card.OnMouseUp {}

Where Card extends PictureBox. I wanted to use

handles sender.OnMouseUp

But I realized that it would not work as sender is a parameter (or would it). Anyways, thanks for your time for looking at this and I hope you guys can solve my problem.

  • By the way if any of the syntax is wrong I did this on my phone while I was away from the computer and Google Docs doesn't give me syntax errors except for the ones that occur in the English language. – Yucheng Niu Dec 31 '17 at 02:47
  • 1
    It will be more better if you can post completely what you have tried – Hameed Syed Dec 31 '17 at 03:36

1 Answers1

0

Add this function to your Card class. Whenever mouse up is called, it'll call your function too.

protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            Play(this, e);
        }
Ctznkane525
  • 7,297
  • 3
  • 16
  • 40