How to Change button image on MouseHover,MouseLeave and MouseClick in windows forms C#.net || Button Events in Window form C#.net


In this I am showing about to change button image when we mouse hover on button,mouse leave on button and mouse click.

For that take one Form and add one button control from toolbox and add three images as normal Login button name as login_normal  ,mousehover Login button name as  login_hover  and mouseclick Login button image name as login_pressed for changing button images.

Then select button control properties and set image as normal image button.

Then write the following code in different events:


//for changing button image when mouse hover

private void btnLogin_MouseHover(object sender, EventArgs e)
        {
            this.btnLogin.Image = Properties.Resources.login_hover;
            this.Cursor = Cursors.Hand;   //to change cursor symbol

        }

//for changing button image when mouse leave

        private void btnLogin_MouseLeave(object sender, EventArgs e)
        {
            this.btnLogin.Image = Properties.Resources. login_normal ;
            this.Cursor = Cursors.Arrow; //to change cursor symbol
        }

//for changing button image when mouse click

        private void btnLogin_MouseDown(object sender, MouseEventArgs e)
        {
            this.btnLogin.Image = Properties.Resources. login_pressed;
            this.Cursor = Cursors.Arrow; //to change cursor symbol
        }

Then run application and see output with button image changing on mouse hover, mouse leave and mouse click.




1 comment:

  1. Way cool! Some very valid points! I appreciate
    you writing this write-up plus the rest of the website is also
    really good.

    Here is my web-site: Read This

    ReplyDelete