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}";
    }
}
相关推荐
坐吃山猪3 分钟前
Python-JsonRPC
开发语言·python
小毛驴8506 分钟前
Windows环境,Python实现对本机处于监听状态的端口,打印出端口,进程ID,程序名称
开发语言·windows·python
MyhEhud15 分钟前
Kotlin zip 函数的作用和使用场景
开发语言·windows·kotlin
火龙谷16 分钟前
【工具推荐】Code2Prompt
开发语言
阿蒙Amon18 分钟前
DevExpress&WinForms-布局之SplitContainerControl
c#·devexpress·winforms
code monkey.23 分钟前
【探寻C++之旅】第十三章:红黑树
开发语言·数据结构·c++
黄雪超34 分钟前
JVM——Java内存模型
java·开发语言·jvm
南玖yy1 小时前
C++ 工具链与开发实践:构建安全、高效与创新的开发生态
开发语言·c++·人工智能·后端·安全·架构·交互
哎哟喂_!1 小时前
Node.js vs 浏览器中的JavaScript:区别全解析
开发语言·javascript·node.js
androidwork1 小时前
Kotlin Coroutine与Retrofit网络层构建指南
开发语言·kotlin·retrofit