Click here to Skip to main content
15,391,989 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I need a codeproject that does the following:
I have a loop that adds pictures to the screen while loading the window.
The purpose is a card game, and I am trying to do that when me (the player) enters one of his cards with the cursor - the card goes a little up,
I know that it is something with the mouse events, MOUSEENTER something like that
But I didn't manage to make it work on the pictures I add.

The real problem is that I can't name those pictures because it's like 60-70 pictures and I don't think the answer is making 70 PICTUREBOXes and on everyone of them making a MOUSE EVENT FUNCTION

Please help!!!!
Thanx a lot ♥
Posted

As you add the pictures to the form, register a MouseEnter event for it. At that point, you can determine which picture caused the event.
   
v2
Comments
Marlenbend 5-Dec-11 15:11pm
   
Can I send you my c# file and you'll see the problem ?
Manfred Rudolf Bihy 5-Dec-11 15:39pm
   
You can work this out yourself. What John meant was that you only need one event handler which can be attached to every picturebox you generate. If you look carefully at the definition of the click event handlers arguments you'll see that a reference to the clicked on picturebox is passed to the handler. So if you keep track of the association between the pictureboxes and the corresponding cards it will be easy to figure out which card was accessed by said click.
void p_MouseEnter(object sender, EventArgs e)
{
    PictureBox p = (PictureBox)sender;
    p.SetBounds(p.Bounds.X, 650, 75, 120);
    Controls.Add(this.p);
}


void p_MouseLeave(object sender, EventArgs e)
{
    PictureBox p = (PictureBox)sender;
    p.SetBounds(p.Bounds.X, 680, 75, 120);
    Controls.Add(p);
}


THANK YOU FOR YOUR HELP!!!!!!!!!!!!!!!!!! ♥ ♥ ♥
   
v3
Comments
Smithers-Jones 7-Dec-11 6:44am
   
Added code-block.
void pt_MouseEnter(object sender, EventArgs e)
{
PictureBox pt = (PictureBox)sender;
pt.SetBounds(pt.Bounds.X, 520, 70, 100);
Controls.Add(this.pt);
}

void pt_MouseLeave(object sender, EventArgs e)
{
PictureBox pt = (PictureBox)sender;
pt.SetBounds(pt.Bounds.X, 550, 75, 100);
Controls.Add(pt);
}
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900