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}";
    }
}
相关推荐
Aurorar0rua3 分钟前
CS50 x 2024 Notes C - 04
java·开发语言
iCxhust7 分钟前
C#程序,窗体1向窗体2的textbox控件写入字符串“hello”
开发语言·c#
低客的黑调13 分钟前
Redis-不止是缓存
java·开发语言·数据库
花间相见17 分钟前
【大模型微调与部署02】—— ms-swift 自定义数据集完全教程:格式、dataset_info 配置、多格式兼容实战
开发语言·ssh·swift
Hello--_--World21 分钟前
JS:闭包、函数柯里化、工厂函数、偏函数、立即执行函数 相关知识点与面试题
开发语言·javascript·ecmascript
一只幸运猫.25 分钟前
字节跳动Java大厂面试版
java·开发语言·面试
xier_ran34 分钟前
【C++】“内部”、“外部”、“派生类”、“友元“类
java·开发语言·c++
im_AMBER42 分钟前
从面试题看JS变量提升
开发语言·前端·javascript·前端框架
故事和你9142 分钟前
洛谷-数据结构1-2-二叉树1
开发语言·数据结构·c++·算法·leetcode·动态规划·图论
大橘43 分钟前
【qml-5.1】qml与c++交互(QML_ELEMENT/QML_SINGLETON)
开发语言·c++·qt·交互·qml