Link to home
Start Free TrialLog in
Avatar of securedungeon
securedungeon

asked on

PictureBox MouseHover

the mousehover events does not work as per in the code.

it is suppose to be when mousehover, a picturebox will appear and when mouseLeave the picture will automatically hide it away.

pls guide. thank u.
private Point mouseLocation = new Point(0, 0);


 public Form1()
        {
            InitializeComponent();

            string ImagePath = Application.StartupPath + @"\PP\";

            string[] Images = new string[] { ImagePath + "Button.jpg"};

            foreach (string img in Images)
            {
                PictureBox PB = new PictureBox();
                PB.Width = 43;
                PB.Height = 43;
                PB.Location = new Point(12, 24);
                PB.Image = Image.FromFile(img);
                PB.MouseDown += new MouseEventHandler(PB_MouseDown);
                this.Controls.Add(PB);

            }
        }

        int x;
        int y;

        void PB_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                x = e.X;
                y = e.Y;


                PictureBox pictureBox = new PictureBox();
                pictureBox.Image = ((PictureBox)sender).Image;
                pictureBox.Width = ((PictureBox)sender).Width;
                pictureBox.Height = ((PictureBox)sender).Height;
                pictureBox.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
                pictureBox.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
                this.Controls.Add(pictureBox);
                pictureBox.BringToFront();

                MouseUPDOWN();

            }
        }



///////the MOUSEHOVER AND MOUSELEAVE codes.
     void PB_MouseHover(object sender, EventArgs e)
        {
            mouseLocation = this.PointToClient(Cursor.Position);
            pictureBox3.Location = mouseLocation;
            pictureBox3.Show();
        }

        void PB_MouseLeave(object sender, EventArgs e)
        {
            pictureBox3.Hide();
        }

Open in new window

Avatar of mikebirt
mikebirt
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

rather than calling Show and Hide, use the Visible property. Set it to false to hide your control and true to show it.

HTH

Mike
Avatar of securedungeon
securedungeon

ASKER

eh, i wanted the mousehover events handler to imply on the multiple pictureboxs that i had created.
Hi,

I Guess i misunderstood your question? I'm not sure i understand what you're trying to achieve and what you want help with exactly. You want to apply your event handlers to all the picture boxes you've created? Or the handlers don't work? Also, in your sample you're calling a method MouseUPDOWN, which is not included in the sample.

If you're able to further clarify your problem we may be able to better target any responses.

HTH

Mike
apply the mousehover and mouseleave events for all the pictureboxes that i had created and applying the codes above does not work for it at all..
ASKER CERTIFIED SOLUTION
Avatar of SiliconXP
SiliconXP
Flag of Zambia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it does not work.

what i meant was i had created multiple pictureboxs and they are suppose to have all mousehover events.

however, it does not mousehover for all pictureboxes only got one that has mousehover events.
it been solved.
the solution is provided should be marked as answer. the issue of the getting the events on one picturebox is due to the author load one picture in the image array as seen in the code he submited.