每10秒运行一次功能
本文关键字:一次 功能 10秒 运行 | 更新日期: 2023-09-27 17:59:37
我需要每10秒运行一次函数addFirstSlide
,但我不知道如何以及在哪里执行。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addFirstSlide()
{
PowerPoint.Slide firstSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides[1];
PowerPoint.Shape textBox2 = firstSlide.Shapes.AddTextbox(
Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 50, 500, 500);
textBox2.TextFrame.TextRange.InsertAfter("firstSlide");
}
}
将计时器控件拖到窗体上,并将其.Interval
属性设置为10000(1秒=1000)。然后将代码放入计时器的Tick
事件中。启用计时器后,Tick中的代码将每10秒运行一次。
如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addFirstSlide()
{
PowerPoint.Slide firstSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides[1];
PowerPoint.Shape textBox2 = firstSlide.Shapes.AddTextbox(
Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 50, 500, 500);
textBox2.TextFrame.TextRange.InsertAfter("firstSlide");
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
addFirstSlide();
}
}
}