示例#1
0
        void TextBox1MouseMove(object sender, MouseEventArgs e)
        {
            int chIdx = ((TextBox)sender).GetCharIndexFromPosition(e.Location);

            segmCoord sc = QueryParser.GetSubstrSegmByCharNum(((TextBox)sender).Text, chIdx);

            if (!sc.isEmpty)
            {
                outerKeyz.SelectionStart  = sc.start;
                outerKeyz.SelectionLength = sc.fin - sc.start + 1;
            }

            selColumn = outerKeyz.SelectedText;
        }
示例#2
0
        void RichTextBox2SelectionChanged(object sender, EventArgs e)
        {
            GetSelectionRowCol(this.richTextBox2, this.richTextBox2.SelectionStart);
            rowcolCtrl.Text = "Ln " + (ROW + 1).ToString() + " col " + (COL + 1).ToString();

            if ((!selChangedProgr) && (this.richTextBox2.SelectionLength == 0))
            {
                segmCoord rez;
                rez = GetSelectionRowCol(this.richTextBox2, this.richTextBox2.SelectionStart);
                int oldSelStart = this.richTextBox2.SelectionStart;

                if (ROW >= this.richTextBox2.Lines.Length)
                {
                    return;
                }
                ;
                segmCoord substrToUpdate;
                substrToUpdate = QueryParser.GetSubstrSegmByCharNum(this.richTextBox2.Lines[ROW], COL);

                string parseSubstr = "";
                if ((substrToUpdate.fin == 0) && (substrToUpdate.start == 0))
                {
                    parseSubstr = this.richTextBox2.Lines[ROW];
                    parseSubstr = (string.IsNullOrEmpty(parseSubstr.Trim())) ? "###" : parseSubstr;
                }
                char[] abr = { '(', ')' };
                parseSubstr = (string.IsNullOrEmpty(parseSubstr.Trim())) ? this.richTextBox2.Lines[ROW].Substring(substrToUpdate.start, (substrToUpdate.fin - substrToUpdate.start + 1)) : parseSubstr.Trim();
                parseSubstr = (QueryParser.EnumCharOccurrence(parseSubstr, abr) > 1) ? "" : parseSubstr;
                if ((parseSubstr.EndsWith(")")) || (parseSubstr.StartsWith("(")) || (parseSubstr.StartsWith(")")) || (parseSubstr.Contains("(")))
                {
                    if (!brUnmarked)
                    {
                        UnmarkBr();
                    }

                    brUnmarked        = false;              // draving new, so mark is present
                    pevOpenBr.Current = oldSelStart - 1;

                    #region coloring

                    selChangedProgr = true;
                    this.richTextBox2.SelectionStart = oldSelStart - 1;
                    selChangedProgr = true;
                    this.richTextBox2.SelectionLength    = 1;
                    this.richTextBox2.SelectionBackColor = Color.Orange;
                    selChangedProgr = true;
                    this.richTextBox2.SelectionLength = 0;
                    selChangedProgr = true;
                    this.richTextBox2.SelectionStart = oldSelStart;

//					selChangedProgr = true;
//					this.richTextBox2.SelectionLength = 0;

                    int enclose = GetBrPairPos(this.richTextBox2, oldSelStart, parseSubstr);
                    prevClosBr.Current = enclose - 1;
                    if (enclose >= 0)
                    {
                        selChangedProgr = true;
                        this.richTextBox2.SelectionStart = enclose - 1;
                        selChangedProgr = true;
                        this.richTextBox2.SelectionLength    = 1;
                        this.richTextBox2.SelectionBackColor = Color.Orange;
                        selChangedProgr = true;
                        this.richTextBox2.SelectionLength = 0;
                        selChangedProgr = true;
                        this.richTextBox2.SelectionStart = oldSelStart;
                    }
                    else
                    {
                        MessageBox.Show(" Enclosing bracket not found ! \n Error raise when parse such text");
                    }

                    #endregion
                }
            }
            selChangedProgr = false;
        }
示例#3
0
        // one word (in edit) coloring
        void RichTextBox2KeyUp(object sender, KeyEventArgs e)
        {
            char c = (char)e.KeyValue;             //32 , 8, 46

            if (((e.KeyValue == 32) || (e.KeyValue == 8) || (e.KeyValue == 46)) && (this.richTextBox2.Lines.Length > 0))
            {
                c = 'a';
            }

            #region go to encloset position
            if (Math.Abs(pevOpenBr.Current - prevClosBr.Current) > 150)
            {
                if (pevOpenBr.Current == this.richTextBox2.SelectionStart)
                {
                    selChangedProgr = true;
                    this.richTextBox2.SelectionStart = prevClosBr.Current + 1;
                    return;
                }
                if (prevClosBr.Current == this.richTextBox2.SelectionStart)
                {
                    selChangedProgr = true;
                    this.richTextBox2.SelectionStart = pevOpenBr.Current + 1;
                    return;
                }
            }
            #endregion

            if ((e.KeyCode == Keys.Z) && (e.Control))
            {
                this.richTextBox2.Undo();
            }

            if ((Char.IsLetterOrDigit(c) == false) || (e.Control))
            {
                return;
            }

            if ((this.richTextBox2.ReadOnly) || (this.richTextBox2.Text.Length < 3))
            {
                return;
            }

            if (!brUnmarked)
            {
                UnmarkBr();
            }


            this.richTextBox2.SelectionColor = Color.Black;
            segmCoord rez;
            rez = GetSelectionRowCol(this.richTextBox2, this.richTextBox2.SelectionStart);
            int oldSelStart = this.richTextBox2.SelectionStart;

            segmCoord substrToUpdate;
            string    procRow = this.richTextBox2.Lines[ROW];
            substrToUpdate = QueryParser.GetSubstrSegmByCharNum(procRow, COL);


            if ((substrToUpdate.fin == 0) && (substrToUpdate.start == 0))
            {
                return;
            }
            selChangedProgr = true;
            this.richTextBox2.SelectionStart = rez.start + substrToUpdate.start;
            selChangedProgr = true;
            int len = (substrToUpdate.fin - substrToUpdate.start + 1);
            len = (procRow.Length > len) ? len : len - 1;
            this.richTextBox2.SelectionLength = len;

            string   parseSubstr = procRow.Substring(substrToUpdate.start, len);
            string[] t;
            string   exprType = QueryParser.GetExpresionStruct(QueryParser.TrimBrackets(parseSubstr), out t);


            this.richTextBox2.SelectionColor     = GetColorByExpr(exprType);
            this.richTextBox2.SelectionBackColor = Color.White;
            selChangedProgr = true;
            this.richTextBox2.SelectedText = parseSubstr;
            selChangedProgr = true;
            this.richTextBox2.SelectionStart = oldSelStart;
        }