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

securedungeonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikebirtCommented:
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
0
securedungeonAuthor Commented:
eh, i wanted the mousehover events handler to imply on the multiple pictureboxs that i had created.
0
mikebirtCommented:
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
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

securedungeonAuthor Commented:
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..
0
SiliconXPCommented:
it looks to me like you are trying to make a UI with rollover effects.i stand to be corrected. if that is the case, then you are better off with a ToolStrip.

however for the code you gave, make the following changes and it should work fine

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);
                PB.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
                PB.MouseDown += new MouseEventHandler(pictureBox1_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 = (PictureBox)sender);
               // 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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
securedungeonAuthor Commented:
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.
0
securedungeonAuthor Commented:
it been solved.
0
SiliconXPCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.