所以我试图编写一个代码,每 750 毫秒更改一次文本框中的文字字体(arial、times new roman 等),但我做不到

so I was trying to make a code that changes the writings font(arial,times new roman etc.) in the textbox every 750 miliseconds but I couldn't do it

private void OnTimer(object sender, EventArgs e)
{
    int i = 0;
    i += 1;
}

我试过制作定时器

private void Form1_Load(object sender, EventArgs e)
{
    int i = 0;
    FontFamily[] fontlar = FontFamily.Families;
    fontlar.GetUpperBound(i);

    Timer timer1 = new Timer
    {
        Interval = 750
    };
    timer1.Enabled = true;
    timer1.Tick += new System.EventHandler(OnTimer);
}

我将代码放在 form1 中,但我在文本框中也尝试过它,但它没有用

private void button1_Click(object sender, EventArgs e)
{
    timer1.Enabled = true;
}

按钮

我猜你是新手。

  1. 你的计时器什么都不做
  2. 你的定时器是本地的,应该是public
  3. 您没有创建文本框

我想这就是你的答案:

 Timer timer1;
    int i = 0;
    private void Form1_Load(object sender, EventArgs e)
    {
        timer1 = new Timer
        {
            Interval = 750
        };
        timer1.Enabled = true;
        timer1.Tick += new System.EventHandler(OnTimer);
    }
    private void OnTimer(object sender, EventArgs e)

    {
        i += 1;
        FontFamily[] fontlar = FontFamily.Families;
        //fontlar.GetUpperBound(i);
        textBox1.Font = new Font(fontlar[i], 16.0f);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        timer1.Enabled = true;
    }

不要忘记在您的表单上创建一个文本框。