C# WPF编程-RepeatButton

RepeatButton(重复按钮)

在WPF中,RepeatButton是一个特殊的按钮控件,它与普通Button的主要区别在于它可以自动重复触发点击事件,只要用户持续按下按钮不放。这对于需要连续执行某个操作的场景非常有用,例如滚动条、音量控制等。

主要属性:

  • Delay:定义了从按下按钮到首次触发Click事件的时间间隔(以毫秒为单位)。默认值是500毫秒。
  • Interval:定义了之后每次触发Click事件之间的时间间隔(以毫秒为单位)。默认值是50毫秒。
xml 复制代码
<StackPanel Orientation="Horizontal">
    <RepeatButton Width="100" Height="50" Delay="500" Interval="30" Content="增加" Click="RepeatButton_Increase"/>
    <RepeatButton Width="100" Height="50" Delay="500" Interval="30" Content="减小" Click="RepeatButton_Decrease"/>
    <TextBlock Width="100" FontSize="20" x:Name="textBlockNumber"/>
</StackPanel>
csharp 复制代码
public partial class WindowButtonDemo : Window
{
    private int number=1;
    public WindowButtonDemo()
    {
        InitializeComponent();
    }

    private void RepeatButton_Increase(object sender, RoutedEventArgs e)
    {
        number++;
        textBlockNumber.Text = $"数值:{number}";
    }

    private void RepeatButton_Decrease(object sender, RoutedEventArgs e)
    {
        if (number > 0) number--;
        textBlockNumber.Text = $"数值:{number}";
    }
}
相关推荐
豐儀麟阁贵6 分钟前
5.6对象
java·开发语言
郝学胜-神的一滴29 分钟前
QAxios研发笔记(二):在Qt环境下基于Promise风格简化Http的Post请求
开发语言·c++·笔记·qt·网络协议·程序人生·http
敲代码的嘎仔32 分钟前
数据结构算法学习day3——二分查找
java·开发语言·数据结构·学习·程序人生·算法·职场和发展
m5655bj1 小时前
如何使用 Python 转换 Excel 工作表到 PDF 文档
开发语言·c#·excel
ᐇ9591 小时前
Java核心概念深度解析:从包装类到泛型的全面指南
java·开发语言
逻极1 小时前
Rust之旅的起点:为什么选择Rust?
开发语言·后端·rust
Tony Bai1 小时前
从 Python 到 Go:我们失去了什么,又得到了什么?
开发语言·后端·python·golang
华如锦1 小时前
使用SSE进行实时消息推送!替换WebSocket,轻量好用~
java·开发语言·网络·spring boot·后端·websocket·网络协议
wudl55662 小时前
python字符串处理与正则表达式--之八
开发语言·python·正则表达式
技术支持者python,php2 小时前
SUB设备电子狗加密狗开发
c#