-2

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

  • let me know that wokred for you or not ?? and do accept/upvote if it works for you – Pranay Rana Dec 12 '17 at 09:36
  • @Synthwave is it wpf or Winform? You should restructure your question entirely if necessary copy paste the content from that link. – tabby Dec 12 '17 at 09:41

2 Answers2

2

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);
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0

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>

tabby
  • 1,878
  • 1
  • 21
  • 39