C# 如何在x秒内自动选择下一个组合框选择?

C# 如何在x秒内自动选择下一个组合框选择?,c#,winforms,C#,Winforms,使用C,windows窗体 我试图让程序每x秒自动选择组合框中的下一项,一旦它到达最后一项,它就会返回到列表中的第一项。除了自动组合框选择部分,我几乎什么都有 请帮忙 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e)

使用C,windows窗体

我试图让程序每x秒自动选择组合框中的下一项,一旦它到达最后一项,它就会返回到列表中的第一项。除了自动组合框选择部分,我几乎什么都有

请帮忙

    public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }       

    private void Form1_Load(object sender, EventArgs e)
    {
        //pictureBox1.Image = Image.FromFile(@"Z:\DSCF1661.jpg");

        DirectoryInfo test = new DirectoryInfo(@"C:\temp");//Assuming Test is your Folder
        FileInfo[] Files = test.GetFiles("*.pdf"); //Getting Text files

        comboBox1.DataSource = Files;
        comboBox1.DisplayMember = "Name";
        timerset();
    }


    public void axSetting()
    {
        axAcroPDF1.setShowToolbar(false);
        axAcroPDF1.setView("FitH");
        axAcroPDF1.setPageMode("none");
        axAcroPDF1.setLayoutMode("SinglePage");
        axAcroPDF1.Show();
    }



    private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
    {
        axAcroPDF1.LoadFile(@"C:\temp\" + comboBox1.Text);
        axAcroPDF1.src = @"C:\temp\" + comboBox1.Text;
        axSetting();

    }
    //private System.Windows.Forms.Timer timer1;


    public void comboBoxSelect()
    {
        if (comboBox1.SelectedIndex < comboBox1.Count) // this part... :(
        {
            comboBox1.SelectedIndex += 1;
        }
        else
        {
            comboBox1.SelectedIndex = 0;
        }
    }

    public void timerset()
    {
        timer1 = new System.Windows.Forms.Timer();
        timer1.Tick += new EventHandler(timer1_Tick);
        timer1.Interval = 5000; // in miliseconds
        timer1.Start();
    }
    private void timer1_Tick(object sender, EventArgs e)
    {
        comboBoxSelect();
    }
这应该起作用:

if(combobox.SelectedIndex < (combobox.Items.Count -1))
{
    combobox.SelectedIndex += 1;
}
else
{
    combobox.SelectedIndex = 0;
} 

首先获取系统空闲时间的目的是什么?你的计时器做不到的是什么?这看起来真的是一个错误。您的实际功能需求是什么?为什么选择使用系统的空闲时间?在不知道节目应该做什么的情况下,很难给你一个如何做得更好的想法。这是为了制作一个宣传节目。它假设从共享文件夹抓取文件,当播音员将新文件放入共享文件夹时,它会在屏幕上显示该文件。这台电脑将始终处于空闲状态,因此每10秒它将显示下一个文件。或者我可以在组合框中每隔一秒选择下一项,而不是使用空闲时间,因为电脑将一直处于空闲状态。@shin777如果电脑仍处于空闲状态,为什么不通过Thread.Sleep10000每10秒检查一次呢?如果您不希望主线程被文件读取或其他内容阻塞,您可以在另一个线程中检查新文件。combobox.source.count不工作。。我正在使用FileInfo和*.pdf从文件夹中筛选pdf文件名,而源部件不起作用:凯。改为尝试.Length,如果不起作用,则使用用于指定source.combobox.maxlength的文件数组。现在唯一的问题是。。当它到达最后一个时,我如何使它返回到第一个?我将更新我的答案来告诉你如何。这很简单,这应该是你的解决方案。