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 = "鼠标出入了";
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本