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}";
    }
}
相关推荐
Amumu121385 小时前
JS:ES6~ES11基础语法(二)
开发语言·前端·javascript
Amumu121385 小时前
Js:ES6~ES11基础语法(一)
开发语言·前端·javascript
m0_569881475 小时前
跨语言调用C++接口
开发语言·c++·算法
zdl6865 小时前
搭建Golang gRPC环境:protoc、protoc-gen-go 和 protoc-gen-go-grpc 工具安装教程
开发语言·后端·golang
LilySesy5 小时前
【与AI+】英语day1——ABAP基础与数据类型
开发语言·ai·sap·abap
你不是我我5 小时前
【Java 开发日记】我们来说一下 b+ 树与 b 树的区别
java·开发语言
2501_924952695 小时前
C++中的过滤器模式
开发语言·c++·算法
左左右右左右摇晃6 小时前
Java笔记——IO
java·开发语言·笔记
2401_873204656 小时前
C++中的组合模式实战
开发语言·c++·算法
twc8296 小时前
Query 改写 大模型测试的数据倍增器
开发语言·人工智能·python·rag·大模型测试