c#触发事件

Demo1 触发事件

在这里插入图片描述
在这里插入图片描述

<Window x:Class="WPFExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WPF Example" Height="600" Width="800">
    <Grid>
        <TextBlock x:Name="txtTotal" Text="计算结果" Visibility="Hidden"/>
        <StackPanel>
            <Button  Content="Click me" Height="30" Width="200" Click="Button_Click" HorizontalAlignment="Center" Background="#FFE8DD2C" BorderBrush="#FF3E94ED" MouseEnter="Button_Mouse_Enter" MouseLeave="Button_Mouse_Leave"/>
        </StackPanel>
    </Grid>
</Window>

using System;
using System.Windows;

namespace WPFExample
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int num1 = 10;
            int num2 = 20;
            int total=num1 + num2;

            txtTotal.Text=total.ToString();
            txtTotal.Visibility=Visibility.Visible;
        }

        private void Button_Mouse_Enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            txtTotal.Text = "鼠标进入这个范围了";
            txtTotal.Visibility = Visibility.Visible;
        }

        private void Button_Mouse_Leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            txtTotal.Text = "鼠标移出这个范围了";
            txtTotal.Visibility = Visibility.Visible;
        }
    }
}

相关推荐

  1. oracle 触发器事前触发事后触发区别

    2024-03-09 22:32:03       46 阅读
  2. 事件触发事件捕获与事件冒泡(js的问题)

    2024-03-09 22:32:03       68 阅读
  3. 控制台程序退出时触发事件

    2024-03-09 22:32:03       56 阅读
  4. xss常用标签和触发事件

    2024-03-09 22:32:03       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-09 22:32:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-09 22:32:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-09 22:32:03       82 阅读
  4. Python语言-面向对象

    2024-03-09 22:32:03       91 阅读

热门阅读

  1. markdown学习笔记

    2024-03-09 22:32:03       47 阅读
  2. spring aop中获取request和response

    2024-03-09 22:32:03       43 阅读
  3. 基础算法(二)#蓝桥杯

    2024-03-09 22:32:03       39 阅读
  4. 外挂的本质以及进程相关的内容

    2024-03-09 22:32:03       41 阅读
  5. ElasticSearch聚合查询

    2024-03-09 22:32:03       35 阅读
  6. CSS 工程结构

    2024-03-09 22:32:03       47 阅读
  7. Pytest教程:Pytest参数化测试

    2024-03-09 22:32:03       50 阅读
  8. SQL 中IN 列表的最佳使用情况

    2024-03-09 22:32:03       45 阅读