C#代码事件

给按钮添加点击事件#

给 Button 添加属性 Click,在button后任意地方输入Click,在选择,创建Button_Click事件(将事件绑定到新创建的名为Button_Click)

 private void Button_Click(object sender, RoutedEventArgs e){}

设置TextBlock的隐藏与实现(Visibility)#

Visibility有三种用法,
第一个:Visible 元素在窗体中正常显示
第二个:Collaspsed 元素不显示,也不占用空间
第三个:Hidden 元素不显示,但是任然为它保留空间

在xaml#

 <Grid>
    <StackPanel>
        <TextBlock x:Name="txtTotal" Text=" 开始计算" Visibility="Hidden"/>
        <Button Content="计算结果=" Click="Button_Click" Height="100"  Width=" 200" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave"/>


    </StackPanel>

在cs中#

private void Button_Click(object sender, RoutedEventArgs e)
{
    int nub1 = 200;
    int nub2 = 300;
    int he   =nub1+ nub2;
    txtTotal.Text =Convert.ToString(he);
    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 = "鼠标出入了";
   
}
posted @   神乐羊  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示
主题色彩