MouseHover Events

I created pictureboxes for different images and i need to mousehover to each image.

and i implemented some codes but it is not working.

Please guide.
thank u.
private Point mouseLocation = new Point(0, 0);
        public Form1()
        {
            InitializeComponent();
            string ImagePath = Application.StartupPath + @"\\Model Products v3\";

            string[] Images = new string[] { ImagePath + "FingerprintScanner1Button.jpg", ImagePath + "FingerprintScanner2Button.jpg", ImagePath + "FingerprintScanner3Button.jpg" };

        
            int X = 0;
            foreach (string img in Images)
            {
                PictureBox PB = new PictureBox();
                PB.Width = PB.Height = 43;
                PB.Location = new Point(44 * X, 24);
                PB.Image = Image.FromFile(img);
                PB.MouseDown += new MouseEventHandler(PB_MouseDown);
             //   PB.MouseHover += new MouseEventHandler(PB_MouseHover);
                this.Controls.Add(PB);
                X++;
            }
        }

        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.Top = ((PictureBox)sender).Top;
                pictureBox.Width = ((PictureBox)sender).Width;
                pictureBox.Height = ((PictureBox)sender).Height;
                pictureBox.Left = ((PictureBox)sender).Left;
                pictureBox.MouseMove += new MouseEventHandler(PictureBox_MouseMove);
                pictureBox.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
                this.Controls.Add(pictureBox);
                pictureBox.BringToFront();

                MouseUPDOWN();

            }
        }
        void PB_MouseHover(object sender, MouseEventArgs e)
        {
            mouseLocation = this.PointToClient(Cursor.Position);
            pictureBox1.Location = mouseLocation;
            pictureBox1.Show();
            pictureBox1.BringToFront();


        }

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

        void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
           
           if (e.Button == MouseButtons.Left)
           {

                ((PictureBox)sender).Left += (e.X - x);
                ((PictureBox)sender).Top += (e.Y - y);
                ((PictureBox)sender).BringToFront();
           }
        }

Open in new window

securedungeonAsked:
Who is Participating?
 
securedungeonAuthor Commented:
But there is an  Error : Cannot implicitly convert type 'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'.

0
 
SriVaddadiCommented:
You have commented the MouseHover event handler registration

//   PB.MouseHover += new MouseEventHandler(PB_MouseHover);
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It should be:

    PB.MouseHover += new EventHandler(PB_MouseHover);

With the method looking like:

        void PB_MouseHover(object sender, EventArgs e)
        {
           
        }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.