1

我正在使用计时器和数组创建一个基于 Windows 表单的多击(旧电话键盘)类型系统。但是,每当我单击按钮以将文本附加到文本框时,菜单会垂直删除重复项,我不知道为什么似乎我已经注意到在我的 CS 中引用了菜单字符串。代码本身还没有完成,我只是想阻止这种重复的发生,并将数组中的字符实际附加到富文本框。任何帮助将不胜感激,谢谢!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

    namespace Mini_Keyboard
    {
        public partial class MiniKeyboard : Form
        {
            public MiniKeyboard()
            {
                InitializeComponent();
            }

            string currentMode = "Multi Tap"; // Sets the mode of the app on startup to be "Multi Tap"
            int intIntervalRequired = 1000; // Time interval in which the user has to switch through the characters
            string currentKey;
            string prevKey;
            int currentIndex = -1;
            string[] keyPad1 = new string[7] { ".", "~", "\"", "1", "'", ":", ";" }; // Characters for key 1
            string[] keyPad2 = new string[7] { "a", "b", "c", "2", "A", "B", "C" }; // Characters for key 2
            string[] keyPad3 = new string[7] { "d", "e", "f", "3", "D", "E", "F" }; // Characters for key 3
            string[] keyPad4 = new string[7] { "g", "h", "i", "4", "G", "H", "I;" }; // Characters for key 4
            string[] keyPad5 = new string[7] { "j", "k", "l", "5", "J", "K", "L" }; // Characters for key 5
            string[] keyPad6 = new string[7] { "m", "n", "o", "6", "M", "N", "O" }; // Characters for key 6
            string[] keyPad7 = new string[9] { "p", "q", "r", "s", "7", "P", "Q", "R", "S" }; // Characters for key 7
            string[] keyPad8 = new string[7] { "t", "u", "v", "8", "T", "U", "V" }; // Characters for key 8
            string[] keyPad9 = new string[9] { "w", "x", "y", "z", "9", "W", "X", "Y", "Z" }; // Characters for key 9
            string[] keyPad0 = new string[2] { "0", " " }; // Characters for key 0
            string[] keyPadStar = new string[3] { "*", "-", "_" }; // Characters for key Star
            string[] keyPadHash = new string[3] { "#", "-", "_" }; // Characters for key Hash
            Timer timer = new Timer();
            public void runTimer()
            {
                InitializeComponent();

                timer.Tick += new EventHandler(stopTimer);
                timer.Interval = intIntervalRequired;
                timer.Enabled = true;
                timer.Start();
            }

            public void stopTimer(object sender, EventArgs e)
            {
                timer.Stop();
                prevKey = currentKey;
                currentKey = "";
                currentIndex = -1;
            }

            private void btnChangeMode_Click(object sender, EventArgs e)
            {
                if (currentMode == "Multi Tap") // If the current mode is "Multi Tap", change it to "Prediction"
                {
                    currentMode = "Prediction";
                    txtCurrentMode.Text = currentMode;
                }
                else // If the current mode is "Prediction", change it to "Multi Tap"
                {
                    currentMode = "Multi Tap";
                    txtCurrentMode.Text = currentMode;
                }
            }

            private void btnKeyPadNo2_Click(object sender, EventArgs e)
            {
                currentKey = "2";
                appendChar(ref keyPad2);
            }

            public void appendChar(ref string[] key)
            {
                runTimer();
                if (currentIndex == -1)
                {
                    currentIndex++;
                    rtbCurrentString.AppendText(key[currentIndex]);
                }
            }
        }
    }

这是我之前制作的表单的重新编码,它有相同的错误,我决定从头开始修复它,但它没有。

这是问题截屏的链接:

http://i44.tinypic.com/30lkjlk.png

更新:原来模式按钮不再起作用,在这发生之前很好。

4

1 回答 1

1

删除InitializeComponent();in runTimer。它应该在构造函数中调用一次。

您当前的流程是:

appendChar -> runTimer -> InitializeComponent

于 2013-05-03T06:03:07.503 回答