Xmal文件下
<StackPanel>
<Button Content="加法" Click="Button_Click_1" Width="200" Height="50" Background="Green" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"/>
<TextBlock Text="计算结果" x:Name="txtTotal"/>
</StackPanel>
对应的.cs文件
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int num1 = 200;
int num2 = 300;
int total = num1 + num2;
txtTotal.Text = total.ToString();
txtTotal.Visibility =Visibility.Visible;
}
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
txtTotal.Text = "你的鼠标移入到了按钮区域";
txtTotal.Visibility = Visibility.Visible;
}
private void Button_MouseLeave(object sender, MouseEventArgs e)
{
txtTotal.Text = "你的鼠标离开了按钮";
txtTotal.Visibility = Visibility.Visible;
}
}