winforms - C# - Menu Strip Duplicating for no Apparent Reason -
i'm creating windows form based multi tap (old phone keypad) type system, using timers , arrays. however, whenever click button append text text box, menu strips duplicates vertically, have no idea why seem have note referenced menu string in cs. code isn't finished, i'd stop duplication happening, , character array append rich text box. @ appreciated, thanks!
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 mode of app on startup "multi tap" int intintervalrequired = 1000; // time interval in user has switch through characters string currentkey; string prevkey; int currentindex = -1; string[] keypad1 = new string[7] { ".", "~", "\"", "1", "'", ":", ";" }; // characters key 1 string[] keypad2 = new string[7] { "a", "b", "c", "2", "a", "b", "c" }; // characters key 2 string[] keypad3 = new string[7] { "d", "e", "f", "3", "d", "e", "f" }; // characters key 3 string[] keypad4 = new string[7] { "g", "h", "i", "4", "g", "h", "i;" }; // characters key 4 string[] keypad5 = new string[7] { "j", "k", "l", "5", "j", "k", "l" }; // characters key 5 string[] keypad6 = new string[7] { "m", "n", "o", "6", "m", "n", "o" }; // characters key 6 string[] keypad7 = new string[9] { "p", "q", "r", "s", "7", "p", "q", "r", "s" }; // characters key 7 string[] keypad8 = new string[7] { "t", "u", "v", "8", "t", "u", "v" }; // characters key 8 string[] keypad9 = new string[9] { "w", "x", "y", "z", "9", "w", "x", "y", "z" }; // characters key 9 string[] keypad0 = new string[2] { "0", " " }; // characters key 0 string[] keypadstar = new string[3] { "*", "-", "_" }; // characters key star string[] keypadhash = new string[3] { "#", "-", "_" }; // characters 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 current mode "multi tap", change "prediction" { currentmode = "prediction"; txtcurrentmode.text = currentmode; } else // if current mode "prediction", change "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]); } } } }
this recode of form made before had same bug, decided start scratch fix it, didn't.
here's link screencap of problem:
update: turns out mode button no longer working, , fine before happened.
remove initializecomponent();
in runtimer
. should called once in constructor.
your current flow is:
appendchar -> runtimer -> initializecomponent
Comments
Post a Comment