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}";
    }
}
相关推荐
专注仿真1 小时前
引擎扩展性与集成设计深度剖析:从 14 个扩展点到 DIS→HLA 演进之路
开发语言·算法·仿真引擎·推演引擎
Best-Wishes1 小时前
科来网络分析系统(技术交流版)使用说明书
开发语言·junit·php
光泽雨2 小时前
路由概念和路由事件 继承链路 RadioButton的事件解析
wpf
代码不停2 小时前
自动化测试(java)
java·开发语言·selenium·自动化
鬼手点金4 小时前
opencode-rules 插件
java·开发语言·前端·人工智能·chrome·git·github
爱上网的小舟4 小时前
星际战士2启动错误怎么办?5种游戏报错解决方法
开发语言·php
阿里嘎多学长5 小时前
2026-10-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
wangchunyu1146 小时前
Python 数据可视化实战入门教程
开发语言·python·信息可视化
学逆向的7 小时前
C 突破编译器限制
c语言·开发语言·网络安全
jimy17 小时前
C++ 虚函数表:基类和派生类共用一张 vtable 吗?
开发语言·c++