How would I make two buttons appear the same when one is hovered over?
Picture of the buttons I want to be shown are here:
http://i.stack.imgur.com/b4P6B.png
How would I make the button with the green image in the center appear as the same style (colors, borders, etc...) when the Sign On
one has been hovered over / clicked?
I'm using Windows Forms.
This can be done using event handlers on mouse over/out, but frankly the right choice is to make a usercontrol containing both buttons and use that instead of the two...
Simply add handler for MouseEnter event on your "sign on" button - all you have to do in this very handler then, is changing second button's styles (implementing MouseLeave might be useful too - to revert second button to it's original style).
Code sample:
this.ButtonSignOn.MouseEnter += this.ChangeOtherButton;
this.ButtonSingOn.MouseLeave += this.RevertOtherButtonChanges;
// later on
private void ChangeOtherButton(object sender, EventArgs e)
{
this.OtherButton.ForeColor = Colors.Red;
this.OtherButton.BackColor = Color.Blue;
// more styling ...
}
// mostly same stuff when reverting changes
You could refactor those 2 handlers into one, and simply passing colors, fonts and other styles as you go... but this should be enough anyways.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.