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}";
    }
}
相关推荐
froginwe115 分钟前
JSP 发送邮件
开发语言
沐雪轻挽萤11 分钟前
15. C++17新特性-std::string_view
java·开发语言·c++
不考研当牛马19 分钟前
python 第21课 基础完结(UDP套接字)
开发语言·python·udp
wearegogog12323 分钟前
光伏发电系统最大功率跟踪(MPPT)算法 Matlab 实现指南
开发语言·算法·matlab
小小码农Come on24 分钟前
QML怎么使用C++多线程编程
开发语言·c++
努力进修29 分钟前
【java-数据结构】Java优先级队列揭秘:堆的力量让数据处理飞起来
java·开发语言·数据结构
PGFA30 分钟前
深度剖析 C# LINQ 底层执行机制:别让你的应用内存莫名其妙“爆”掉!
c#·solr·linq
廋到被风吹走31 分钟前
【LangChain4j】Java 生态中最灵活、功能最强大的纯 Java 大模型应用开发框架(支持声明式@AiService与复杂RAG/Agent)
java·开发语言·python
艾克杏32 分钟前
初学Java之范型
java·开发语言
heartbeat..33 分钟前
java中常用的几种加密方式
java·开发语言