public Form1() { InitializeComponent(); Graphics dc = this.CreateGraphics(); // create Graphics object FontInfo KeyFontFormat1 = new FontInfo( "Arial", 12f, FontStyle.Bold); BoardKey1 = new BoardKey(PositionLeft, PositionRight, KeySizeSqu, dc, KeyFontFormat1); this.Show(); // show control box to user top = -1; top_buffer = -1; string s_val = System.String.Empty; }
private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && ((e.X >= PositionLeft) && (e.X <= PositionLeft + 10 * KeySizeSqu) && (e.Y <= PositionRight + 4 * KeySizeSqu) && (e.Y >= PositionRight))) {//first time button click CatchStart = true;//change state to start painting top = -1; ColorCord tmp = new ColorCord("", -1, -1, -1, -1, false); Word = ""; key_old = ""; tmp = BoardKey1.ConvCoord2String(PositionLeft, PositionRight, e.X, e.Y, KeySizeSqu, Max_SquMinDistance); if (tmp.Flag) { WordPosStack[++top] = tmp; //CurvePointIndex[top] = 1; Word += tmp.key; key_old = tmp.key; index_times = 1 ; FontInfo KeyFontFormat1 = new FontInfo("Arial", 12f, FontStyle.Bold); BoardKey1.KeyIndexPlus(WordPosStack[top], KeyFontFormat1, KeySizeSqu, index_times); } } if ( e.Button == MouseButtons.Right && CatchStart) {//right button which cause double ColorCord tmp = new ColorCord("", -1, -1, -1, -1, false); tmp = BoardKey1.ConvCoord2String(PositionLeft, PositionRight, e.X, e.Y, KeySizeSqu, Max_SquMinDistance); if (tmp.Flag && index_times<2) {//Comment: a restriction added: if you click the same key twice, then we only record the key for once //cause there is no English word that has trible same letters WordPosStack[++top] = tmp; Word += tmp.key; key_old = tmp.key; ++index_times; //curve point cal:double letters if (top > 1) { vectoriplus1.X = WordPosStack[top].RX - WordPosStack[top - 1].RX; vectoriplus1.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY; CurvePointIndex[top - 1] = 1; vectori = vectoriplus1; } else if (top == 1) { vectori.X = WordPosStack[top].RX - WordPosStack[top - 1].RX; vectori.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY; CurvePointIndex[top - 1] = 1; } else {//top=0, theorical, no possible this will happen } } } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && top>-1) { CatchStart = false; CurvePointIndex[0] = 1; CurvePointIndex[top] = 1; if(WordPosStack[top].key == " " && top>0) { CurvePointIndex[--top] = 1; } if (top == 0 && WordPosStack[top].key == " ") { this.textBox1.Paste(" "); } else { bool Flag = true; //Word find WordFind: List<string> Result = new List<string>(); Result.Clear(); Result = Org_Word.Find(Word.ToLower(), CurvePointIndex); this.listBox1.Items.Clear(); string tmp = ""; int min_lenth = Word.Length; if (Result.Count != 0) { foreach (string ResultWord in Result) { this.listBox1.Items.Add(ResultWord.ToUpper()); if (Word.Length - ResultWord.Length < min_lenth) tmp = ResultWord.ToUpper(); } } else { if (Flag) { CurvePointIndex = new int[MaxLenthWord]; CurvePointIndex[0] = CurvePointIndex[top] = 1; Flag = false; goto WordFind; } this.listBox1.Items.Add(Word); tmp = Word; } input_buffer[++top_buffer] = tmp; if (tmp.Length > 1) { buffer += tmp + " "; this.textBox1.Paste(tmp + " "); } else if(tmp.Length == 1) { buffer += tmp; this.textBox1.Paste(tmp); } else { } } //Create a new word string Graphics hc = this.CreateGraphics(); hc.Clear(this.BackColor);// if need to save path, then comment this line FontInfo KeyFontFormat1 = new FontInfo("Arial", 12f, FontStyle.Bold); BoardKey1 = new BoardKey(PositionLeft, PositionRight, KeySizeSqu,hc, KeyFontFormat1); Word = ""; top = -1; } if(e.Button == MouseButtons.Right && CatchStart && top>-1) { FontInfo KeyFontFormat1 = new FontInfo("Arial", 12f, FontStyle.Bold); BoardKey1.KeyIndexPlus(WordPosStack[top], KeyFontFormat1, KeySizeSqu, index_times); } }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (CatchStart) { Graphics dc = this.CreateGraphics(); dc.FillEllipse(new SolidBrush(Color.BlueViolet), e.X, e.Y, 10, 12); ColorCord tmp = BoardKey1.ConvCoord2String(PositionLeft, PositionRight, e.X, e.Y, KeySizeSqu, SquMinDistance); if ((tmp.key != key_old) && tmp.Flag) { Word += tmp.key; key_old = tmp.key; WordPosStack[++top] = tmp; index_times = 1; FontInfo KeyFontFormat1 = new FontInfo("Arial", 12f, FontStyle.Bold); BoardKey1.KeyIndexPlus(WordPosStack[top], KeyFontFormat1, KeySizeSqu, index_times); //Curve point cal if (top > 1) { vectoriplus1.X = WordPosStack[top].RX - WordPosStack[top - 1].RX; vectoriplus1.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY; if ((vectoriplus1.X - vectori.X == 0) && (vectoriplus1.Y - vectori.Y == 0)) { CurvePointIndex[top - 1] = 0; } else { CurvePointIndex[top - 1] = 1; } vectori = vectoriplus1; } else if (top == 1) { vectori.X = WordPosStack[top].RX - WordPosStack[top - 1].RX; vectori.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY; CurvePointIndex[top - 1] = 1; } else {//top=0, there is only one point, then do nothing } } if (tmp.key == " ") { CatchStart = false; } dc.Dispose(); } }
internal BoardKey(int PositionLeft, int PositionUp, int KeySizeSqu, Graphics DC,FontInfo _FontInfo ) { dc = DC; PointF pointF; BluePen_Key = new Pen(Color.Blue, 3); font = new Font(_FontInfo.FontName, _FontInfo.FontSize,_FontInfo._FontStyle); sizeF = dc.MeasureString(KeyName[0], font); //boundary calculation: left to right boundary[0,0] = PositionLeft; boundary[0,1] = PositionLeft+firline_KeyNumber*KeySizeSqu; boundary[1,0] = PositionLeft; boundary[1,1] = PositionLeft+Secline_KeyNumber*KeySizeSqu; boundary[2,0] = PositionLeft+KeySizeSqu; boundary[2,1] = PositionLeft+Thrline_KeyNumber*KeySizeSqu; boundary[3,0] = PositionLeft+KeySizeSqu; boundary[3,1] = PositionLeft+Thrline_KeyNumber*KeySizeSqu; boundarybottom = PositionUp + 4 * KeySizeSqu; int iPositionLeft = PositionLeft, iPositionUp = PositionUp; for (int i = 0; i < firline_KeyNumber; ++i) { pointF = new PointF(iPositionLeft + KeySizeSqu / 2 - sizeF.Width / 2, iPositionUp + KeySizeSqu / 2 - sizeF.Height / 2 + 1);// Note: 1 is for correct the position KeyPosition[i].X = (float)iPositionLeft; KeyPosition[i].Y = (float)iPositionUp; dc.DrawRectangle(BluePen_Key, iPositionLeft, iPositionUp, KeySizeSqu, KeySizeSqu); dc.DrawString(KeyName[i], font, Brushes.Black, pointF); iPositionLeft += KeySizeSqu; } iPositionLeft = PositionLeft; iPositionUp += KeySizeSqu; for (int i = firline_KeyNumber; i < Secline_KeyNumber + firline_KeyNumber; ++i) { pointF = new PointF(iPositionLeft + KeySizeSqu / 2 - sizeF.Width / 2, iPositionUp + KeySizeSqu / 2 - sizeF.Height / 2 + 1);// Note: 1 is for correct the position KeyPosition[i].X = (float)iPositionLeft; KeyPosition[i].Y = (float)iPositionUp; dc.DrawRectangle(BluePen_Key, iPositionLeft, iPositionUp, KeySizeSqu, KeySizeSqu); dc.DrawString(KeyName[i], font, Brushes.Black, pointF); iPositionLeft += KeySizeSqu; } iPositionLeft = PositionLeft+KeySizeSqu; iPositionUp += KeySizeSqu; for (int i = Secline_KeyNumber+firline_KeyNumber; i < keyNumver; ++i) { pointF = new PointF(iPositionLeft + KeySizeSqu / 2 - sizeF.Width / 2, iPositionUp + KeySizeSqu / 2 - sizeF.Height / 2 + 1);// Note: 1 is for correct the position KeyPosition[i].X = (float)iPositionLeft; KeyPosition[i].Y = (float)iPositionUp; dc.DrawRectangle(BluePen_Key, iPositionLeft, iPositionUp, KeySizeSqu, KeySizeSqu); dc.DrawString(KeyName[i], font, Brushes.Black, pointF); iPositionLeft += KeySizeSqu; } iPositionLeft = PositionLeft + KeySizeSqu; iPositionUp += KeySizeSqu; dc.DrawRectangle(BluePen_Key, iPositionLeft, iPositionUp, KeySizeSqu * Thrline_KeyNumber, KeySizeSqu); KeyPosition[keyNumver].X = (float)iPositionLeft; KeyPosition[keyNumver].Y = (float)iPositionUp; }
public void KeyIndexPlus(ColorCord pos, FontInfo KeyFont, int KeySizeSqu, int times) { PointF pointF = new PointF(pos.pointF.X + KeySizeSqu - sizeF.Width, pos.pointF.Y ); dc.DrawString(times.ToString(), font, Brushes.Red, pointF); }