簡體   English   中英

C#-沒有明顯原因的菜單條復制

[英]C# - Menu Strip Duplicating for no Apparent Reason

我正在使用計時器和數組創建一個基於Windows窗體的多點擊(舊電話鍵盤)類型的系統。 但是,每當我單擊按鈕以將文本追加到文本框時,菜單就會垂直刪除重復項,我不知道為什么要在CS中引用菜單字符串。 代碼本身還沒有完成,我只是想阻止這種重復發生,並且要使數組中的字符實際附加到Rich Text Box中。 任何幫助將不勝感激,謝謝!

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

更新:原來模式按鈕不再起作用,並且在發生這種情況之前還可以。

刪除InitializeComponent(); runTimer 應該在構造函數中調用一次。

您當前的流程是:

appendChar-> runTimer-> InitializeComponent

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM