Someone could kindly give me a little example of the point "Edit 2" related to this best answer.
unfortunately I do not have enough reputation to post the question on the referrals page.
Thx
Someone could kindly give me a little example of the point "Edit 2" related to this best answer.
unfortunately I do not have enough reputation to post the question on the referrals page.
Thx
as you pointed out question , if you want mouseenter to be get called by mutiple button you can do as below
private void btn_MouseEnter(object sender, EventArgs e)
{
Button btn = sender as Button;
if(btn !=null)
{
btn.UseVisualStyleBackColor = false;
btn.BackColor = Color.Black;
btn .ForeColor = Color.White;
}
}
if you want to call same function multiple times for each button mouse enter than you should assign same function to multiple button mouse enter event handlers.
Example :
Button1.MouseEnter += new EventHandler(this.btn_MouseEnter);
Button2.MouseEnter += new EventHandler(this.btn_MouseEnter);
Not a good idea to define a method and call on each button to show MouseOver Effect as per your Link, instead define style as a resources in Xaml and use it for any button you want.
example:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Green"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>