Friday 10 August 2012

how to change image mousehover

To change image and cursor when mousehover and mouseleave in windows forms  dotnet application follow the below steps:
1.First design one test form with one button name as btnIncome.
2. Change button properties and import two images (mousehover image and mouseleave image) from your system.
In this I am taking two income images with the name income_btn_hover and income_btn_normal.
Then write the following code in btnIncome_MouseHover and btnIncome_MouseLeave event.
To change cursor symbol also I am writing code in mousehover and mouseleave events
private void btnIncome_MouseHover(object sender, EventArgs e)
        {
            this.btnIncome.Image = Properties.Resources.income_btn_hover;
            this.Cursor = Cursors.Hand;
        }
private void btnIncome_MouseLeave(object sender, EventArgs e)
        {
            this.btnIncome.Image = Properties.Resources.income_btn_normal;
            this.Cursor = Cursors.Arrow;
        }
Then run your application then you will get the following output form with one Income normal button .
If you mousehover on Income  button then it will change to Income hover button like below:

No comments:

Post a Comment