为Excelfunction区创build倒数计时器

我正在寻找使用VSTO时单击button1时在excel中创buildfunction区的倒计时器。

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

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>