Esempio n. 1
0
        public void HighlightWord(RichTextBox richText, string stString, LineNumbersControlForRichTextBox.LineNumbersForRichText lnRT)
        {
            Regex           rex          = new Regex(stString);
            MatchCollection mcCollection = rex.Matches(richText.Text);

            //
            // http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx
            //
            IntPtr eventMask    = IntPtr.Zero;
            IntPtr eventMaskLRT = IntPtr.Zero;

            int StartCursorPosition = richText.SelectionStart;
            int EndCursorPosition   = richText.SelectionLength;

            try
            {
                // Stop redrawing:
                SendMessage(richText.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                if (lnRT != null)
                {
                    SendMessage(lnRT.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                }
                // Stop sending of events:
                eventMask = SendMessage(richText.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
                if (lnRT != null)
                {
                    eventMaskLRT = SendMessage(lnRT.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
                }

                foreach (Match mMatch in mcCollection)
                {
                    int startIndex = mMatch.Index;
                    int StopIndex  = mMatch.Length;
                    richText.SelectionColor     = Color.Red;
                    richText.SelectionBackColor = Color.Black;
                    richText.Select(startIndex, StopIndex);
                    richText.SelectionStart     = StartCursorPosition;
                    richText.SelectionLength    = 0;
                    richText.SelectionColor     = Color.Black;
                    richText.SelectionBackColor = Color.White;
                }
            }
            finally
            {
                richText.SelectionStart  = StartCursorPosition;
                richText.SelectionLength = EndCursorPosition;
                richText.ScrollToCaret();
                // turn on events
                SendMessage(richText.Handle, EM_SETEVENTMASK, 0, eventMask);
                if (lnRT != null)
                {
                    SendMessage(lnRT.Handle, EM_SETEVENTMASK, 0, eventMaskLRT);
                }
                // turn on redrawing
                SendMessage(richText.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
                if (lnRT != null)
                {
                    SendMessage(lnRT.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
                }
                SendMessage(richText.Handle, WM_NCPAINT, 0, IntPtr.Zero);
            }
        }
Esempio n. 2
0
        public void MakeUpRichText(RichTextBox richText, string strExt, LineNumbersControlForRichTextBox.LineNumbersForRichText lnRT)
        {
            foreach (CodeMarkUp cmuLookup in codeMarkUps)
            {
                foreach (string strMExt in cmuLookup.strExts)
                {
                    if (strMExt.Equals(strExt))
                    {
                        richText.SelectionLength = 0;
                        richText.SelectionColor  = Color.Black;

                        StringBuilder sbTemp = new StringBuilder();

                        sbTemp.Append("(");

                        bool bFirst = true;
                        foreach (string strKeyword in cmuLookup.strKeyWords)
                        {
                            if (bFirst)
                            {
                                sbTemp.Append(strKeyword + "\\s");
                                bFirst = false;
                            }
                            else
                            {
                                sbTemp.Append("|" + strKeyword + "\\s");
                            }
                        }
                        sbTemp.Append(")");

                        Regex           rex          = new Regex(sbTemp.ToString());
                        MatchCollection mcCollection = rex.Matches(richText.Text);

                        //
                        // http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx
                        //
                        IntPtr eventMask    = IntPtr.Zero;
                        IntPtr eventMaskLRT = IntPtr.Zero;
                        try
                        {
                            // Stop redrawing:
                            SendMessage(richText.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                            if (lnRT != null)
                            {
                                SendMessage(lnRT.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                            }
                            // Stop sending of events:
                            eventMask = SendMessage(richText.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
                            if (lnRT != null)
                            {
                                eventMaskLRT = SendMessage(lnRT.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
                            }

                            int StartCursorPosition = 0;

                            foreach (Match mMatch in mcCollection)
                            {
                                int startIndex = mMatch.Index;
                                int StopIndex  = mMatch.Length;
                                richText.Select(startIndex, StopIndex);
                                richText.SelectionColor  = Color.Blue;
                                richText.SelectionStart  = StartCursorPosition;
                                richText.SelectionLength = 0;
                                richText.SelectionColor  = Color.Black;
                            }
                        }
                        finally
                        {
                            // turn on events
                            SendMessage(richText.Handle, EM_SETEVENTMASK, 0, eventMask);
                            if (lnRT != null)
                            {
                                SendMessage(lnRT.Handle, EM_SETEVENTMASK, 0, eventMaskLRT);
                            }
                            // turn on redrawing
                            SendMessage(richText.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
                            if (lnRT != null)
                            {
                                SendMessage(lnRT.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
                            }
                            SendMessage(richText.Handle, WM_NCPAINT, 0, IntPtr.Zero);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private void CreateRTBAndNumbersList(out FixedRichTextBox richTextBox1, out LineNumbersControlForRichTextBox.LineNumbersForRichText lineNumbersForRichText1)
 {
     richTextBox1 = new FixedRichTextBox();
     richTextBox1.AcceptsTab = true;
     richTextBox1.BackColor = rtbBackColour;
     richTextBox1.ContextMenuStrip = this.contextMenuStrip1;
     richTextBox1.DetectUrls = false;
     richTextBox1.Font = rtbFont;
     richTextBox1.ForeColor = rtbForeColour;
     richTextBox1.Location = new System.Drawing.Point(36, 0);
     richTextBox1.Name = "richTextBox1";
     richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
     richTextBox1.Size = new System.Drawing.Size(528, 362);
     richTextBox1.TabIndex = 0;
     richTextBox1.Text = "";
     richTextBox1.WordWrap = false;
     richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
     scripts.Add(richTextBox1);
     lineNumbersForRichText1 = new LineNumbersControlForRichTextBox.LineNumbersForRichText();
     lineNumbersForRichText1.AutoSizing = false;
     lineNumbersForRichText1.BackColor = System.Drawing.SystemColors.Control;
     lineNumbersForRichText1.BackgroundGradientAlphaColor = System.Drawing.Color.Transparent;
     lineNumbersForRichText1.BackgroundGradientBetaColor = System.Drawing.Color.Transparent;
     lineNumbersForRichText1.BackgroundGradientDirection = System.Drawing.Drawing2D.LinearGradientMode.Horizontal;
     lineNumbersForRichText1.BorderLinesColor = System.Drawing.Color.Transparent;
     lineNumbersForRichText1.BorderLinesStyle = System.Drawing.Drawing2D.DashStyle.Dot;
     lineNumbersForRichText1.BorderLinesThickness = 1F;
     lineNumbersForRichText1.DockSide = LineNumbersControlForRichTextBox.LineNumbersForRichText.LineNumberDockSide.Left;
     lineNumbersForRichText1.GridLinesColor = System.Drawing.Color.Transparent;
     lineNumbersForRichText1.GridLinesStyle = System.Drawing.Drawing2D.DashStyle.Dot;
     lineNumbersForRichText1.GridLinesThickness = 1F;
     lineNumbersForRichText1.LineNumbersAlignment = System.Drawing.ContentAlignment.MiddleRight;
     lineNumbersForRichText1.LineNumbersAntiAlias = true;
     lineNumbersForRichText1.LineNumbersAsHexadecimal = false;
     lineNumbersForRichText1.LineNumbersClippedByItemRectangle = true;
     lineNumbersForRichText1.LineNumbersLeadingZeroes = true;
     lineNumbersForRichText1.LineNumbersOffset = new System.Drawing.Size(0, 0);
     lineNumbersForRichText1.Location = new System.Drawing.Point(-8, 0);
     lineNumbersForRichText1.Margin = new System.Windows.Forms.Padding(0);
     lineNumbersForRichText1.MarginLinesColor = System.Drawing.Color.Transparent;
     lineNumbersForRichText1.MarginLinesSide = LineNumbersControlForRichTextBox.LineNumbersForRichText.LineNumberDockSide.None;
     lineNumbersForRichText1.MarginLinesStyle = System.Drawing.Drawing2D.DashStyle.Solid;
     lineNumbersForRichText1.MarginLinesThickness = 1F;
     lineNumbersForRichText1.Name = "lineNumbersForRichText1";
     lineNumbersForRichText1.Padding = new System.Windows.Forms.Padding(0, 0, 2, 0);
     lineNumbersForRichText1.ParentRichTextBox = richTextBox1;
     lineNumbersForRichText1.SeeThroughMode = false;
     lineNumbersForRichText1.ShowBackgroundGradient = true;
     lineNumbersForRichText1.ShowBorderLines = false;
     lineNumbersForRichText1.ShowGridLines = false;
     lineNumbersForRichText1.ShowLineNumbers = true;
     lineNumbersForRichText1.ShowMarginLines = true;
     lineNumbersForRichText1.Size = new System.Drawing.Size(43, 362);
     lineNumbersForRichText1.TabIndex = 12;
 }