-3

当我输入一封信时,我得到了我在顶部声明的当前时间,但它不起作用,因为在声明的一定时间后,该信没有被锁定。

例如它会在 5 秒后从 p 变为 Q,当我希望它变为 p(然后将字母保存在文本框中)然后 p 再次允许我造词时

这是我的代码:

namespace MiniKeyboardAssignment
{
    public partial class Form1 : Form
    {
        //How long i've set my interval to go for, this means how long my timer will be on for before the current letter is saved//
        int timerinterval = 2000;


        bool button_but1 = true;
        int Button1_clicked = -1;
        bool button_but2 = true;
        int Button2_clicked = -1;
        bool button_but3 = true;
        int Button3_clicked = -1;
        bool button_but4 = true;
        int Button4_clicked = -1;
        bool button_but5 = true;
        int Button5_Clicked = -1;
        bool button_but6 = true;
        int Button6_clicked = -1;
        bool button_but7 = true;
        int Button7_clicked = -1;
        bool button_but8 = true;
        int Button8_clicked = -1;
        bool button_but9 = true;
        int Button9_clicked = -1;
        bool button_but10 = true;
        int Button10_clicked = -1;
        bool button_but12 = true;
        int Button12_clicked = -1;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Mode_TextBox.Text = "Multipress";
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            counter = Convert.ToInt16(textBox1.Text);
            counter++;
            textBox1.Text = Convert.ToString(counter);
            timer1.Enabled = true; 
     }

        private void Button1_Click(object sender, EventArgs e)
        {
            string sequence1 = "1";
            if (button_but1 == true)
            {
                Button1_clicked++;
                textbox.Text = Convert.ToString(ListBox1.Items[Button1_clicked]);
                listBox11.Items.Add(sequence1);
                counter++;
                textBox1.Text = Convert.ToString(counter);
                button_but1 = false;
                timer1.Enabled = true;
            }
            else
            {
                Button1_clicked++;
            }
            characterstring[Convert.ToInt16(textBox1.Text)] = Convert.ToString(ListBox1.Items[Button1_clicked]);
            textbox.Text = characterstring[0] + characterstring[1] + characterstring [2] + characterstring [3] + characterstring [4] + characterstring [5] + characterstring [6] + characterstring [7] + characterstring [8] + characterstring [9] + characterstring [10] + characterstring [11] + characterstring [12] + characterstring [13] + characterstring [14] + characterstring [15] + characterstring [16] + characterstring [17] + characterstring [18] + characterstring [19] + characterstring [20];
        }
4

1 回答 1

1

确保您已正确初始化文本框和计时器:

public Form1()
    {
        InitializeComponent();
        this.textBox1.Text = "1";
        this.timer1.Interval = timerInterval;
        this.timer1.Start();
    }

此外,您不需要在 timer1_Tick 方法中设置 timer1.Enabled。将 Enabled 设置为 true 与调用 Start 相同(在我的示例中,这是在构造函数中完成的)。或者,您可以继续仅在单击 button1 时启用计时器。

于 2013-05-03T03:05:31.477 回答