Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I'm new here, and I'm kinda new to programming as well. I wrote a euchre program as a command line program, and I am converting it to a Windows program. For those who don't know, euchre is a card game involving 3-7 players (most commonly 4) which is most commonly played in the NE US.

(http://en.wikipedia.org/wiki/Euchre)

 

A little background on me - This is my first Windows program, and I am learning as I go. I learned C++ in college, and was only taught command-line programming. I originally wrote this program in C++ as a command-line program, and I converted it to C# for the GUI version. I learned the differences from C++ to C# through an eBook that I found, and from searching Google for any specific information I need to know.

 

So now to the issue... I want to make it so that when a player puts the mouse over a card to select which card to play, the card raises up a little, (right now I have it moving up 30 pixels) and then lowers when the mouse is moved, or the card is selected. I have it working fairly well right now, but when the mouse is placed over the bottom 30 pixels of the card, it bounces up and down repeatedly.

 

I am using PictureBoxes to display the cards, and when the mouse is over the box I change the Y location of the box by -30. I tried moving the box and making it 30 pixels taller, but when I do that, the table top is shown through the bottom of the box, instead of the card behind the selected card.

 

I have been playing with so many ways to fix this issue, and I have run out of ideas. Any help would be much appreciated!

 

If you would like to check out the program, and see specifically what I am talking about, you can find it at [REDACTED] (it is kept in my dropbox public folder)

 

This is the code: (p1c1 is a PictureBox that represents the first card in player 1's hand)

 

//player 1 card 1, mouse over
private void p1c1_MouseEnter(object sender, EventArgs e)
{
      //move card up 30 pixels
      Point point = new Point();
      point.X = this.p1c1.Location.X;
      point.Y = this.p1c1.Location.Y - 30;
      this.p1c1.Location = point;
}

//player 1 card 1, mouse leave
private void p1c1_MouseLeave(object sender, EventArgs e)
{
      //move card down 30 pixels
      Point point = new Point();
      point.X = this.p1c1.Location.X;
      point.Y = this.p1c1.Location.Y + 30;
      this.p1c1.Location = point;
}

Edited by snarfblam
  • Leaders
Posted

havens1515, I edited your post to remove the link. It's best to link to a copy of your project rather than to an executable. That way we're safe from viruses and the like, and we can help you better if we can see the code.

 

Anyways, the root of the problem is that when you move the card up 30 pixels, it causes the mouse to be outside the picture box, raising the MouseLeave event. This causes you to move the PictureBox back, which causes the mouse to re-enter the PictureBox, ad infinitum.

 

The ideal solution would be to do away with the picture boxes and do all the drawing and mouse processing yourself, but that's, like, work.

 

A solution that would involve less work would probably involve a different, more complicated way of detecting that the mouse has moved away from the card. For example, instead of using the MouseEnter and MouseLeave events of the picture box, you could handle the MouseMove event of all the cards, as well as the form. In any MouseMove handler, you would check to see if the mouse has moved outside the normal (unraised) bounds of the currently raised card, and if so, lower it.

[sIGPIC]e[/sIGPIC]
Posted

Thanks for the help. I understood why it was happening (that the mouse was moving outside of the picturebox) but I didn't know of any other way to do it. I'll look into the MouseMove event and see if I can make that work.

 

As I said before, I'm kinda learning as I go here so I'll have to do a little research on how to do that. But at least I have a direction to look in. Thanks again!

Posted
OMG thank you so much! I just got it to work. It was A LOT of code, and a lot more work to get it to work 100% than I thought it would be it would be, but it works! Thanks again for your input!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...