繁体   English   中英

为Excel功能区创建倒数计时器

[英]Create Countdown Timer for Excel Ribbon

我想在单击button1时使用VSTO在Excel中为功能区创建倒数计时器。

到目前为止,这是我的代码:

private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
    TimerLabel.Label = "5:00";
    Convert.ToInt32(TimerLabel.Label);

}

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    TimeSpan TimeDecrease = TimeSpan.FromSeconds(1);\
    TimerLabel.Label = Convert.ToInt32(TimerLabel.Label) - TimeDecrease;
}

}

不知道如何去做。 任何帮助都很棒

这是Ribbon.cs的代码

    private TimeSpan startTimeSpan = new TimeSpan(0,5,0,0);
    private Timer timer = new Timer();
  public void Ribbon_Load(Office.IRibbonUI ribbonUI)
    {
        timer.Interval = 1000;
        this.ribbon = ribbonUI;
        timer.Tick += timer_Tick;
        timer.Start();
    }

    private void timer_Tick(object sender, EventArgs e)
    {
        TimeSpan timeDecrease = TimeSpan.FromSeconds(1);
        startTimeSpan = startTimeSpan - timeDecrease;
        ribbon.InvalidateControl("timerLabel");
    }

    public string timerLabel_getLabel(Office.IRibbonControl control)
    {
        return startTimeSpan.ToString();
    }

    //public void button1_onAction(Office.IRibbonControl control)
    //{
    //    timer.Start();
    //}

这是Ribbon.xml

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui" >
    <ribbon>
        <tabs>
            <tab id="TimerTest" label="Timer">
                <group id="group1" label="group1">
                    <labelControl id="timerLabel" getLabel="timerLabel_getLabel"/>
                    <button id="button1" label="button1" showImage="false" onAction="button1_onAction" />
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM