public void OptionsChanged()
 {
     UpdateMatchingBracket();
     textViewMargin.OptionsChanged();
     caret.RecreateCaret();
     caret.UpdateCaretPosition();
     Refresh();
 }
        public bool ExecuteDialogKey(Keys keyData)
        {
            // try, if a dialog key processor was set to use this
            if (DoProcessDialogKey != null && DoProcessDialogKey(keyData))
            {
                return(true);
            }

            // if not (or the process was 'silent', use the standard edit actions
            IEditAction action = motherTextEditorControl.GetEditAction(keyData);

            AutoClearSelection = true;
            if (action != null)
            {
                motherTextEditorControl.BeginUpdate();
                try
                {
                    lock (Document)
                    {
                        action.Execute(this);
                        if (SelectionManager.HasSomethingSelected && AutoClearSelection /*&& caretchanged*/)
                        {
                            if (Document.TextEditorProperties.DocumentSelectionMode == DocumentSelectionMode.Normal)
                            {
                                SelectionManager.ClearSelection();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got Exception while executing action " + action + " : " + e.ToString());
                }
                finally
                {
                    motherTextEditorControl.EndUpdate();
                    Caret.UpdateCaretPosition();
                }
                return(true);
            }
            return(false);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            int       currentXPos      = 0;
            int       currentYPos      = 0;
            bool      adjustScrollBars = false;
            Graphics  g             = e.Graphics;
            Rectangle clipRectangle = e.ClipRectangle;


            if (updateMargin != null)
            {
                try
                {
                    updateMargin.OnPaint(g, updateMargin.DrawingRectangle);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Got exception : " + ex);
                }
                //clipRectangle.Intersect(updateMargin.DrawingRectangle);
            }

            if (clipRectangle.Width <= 0 || clipRectangle.Height <= 0)
            {
                return;
            }

            if (this.TextEditorProperties.UseAntiAliasedFont)
            {
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            }
            else
            {
                g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            }
            //以下开始画TextArea中的各个区域,同时制定各个区域的Rectangle大小.
            foreach (AbstractMargin margin in leftMargins)
            {
                if (margin.IsVisible)
                {
                    Rectangle marginRectangle = new Rectangle(currentXPos, currentYPos, margin.Size.Width, Height - currentYPos);
                    if (marginRectangle != margin.DrawingRectangle)
                    {
                        adjustScrollBars        = true;
                        margin.DrawingRectangle = marginRectangle;
                    }
                    currentXPos += margin.DrawingRectangle.Width;                    //为画下一个margin提供正确的x坐标。
                    if (clipRectangle.IntersectsWith(marginRectangle))
                    {
                        marginRectangle.Intersect(clipRectangle);
                        if (!marginRectangle.IsEmpty)
                        {
                            try
                            {
                                margin.OnPaint(g, marginRectangle);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Got exception : " + ex);
                            }
                        }
                    }
                }
            }

            Rectangle textViewMarginArea = new Rectangle(currentXPos, currentYPos, Width - currentXPos, Height - currentYPos);

            if (textViewMarginArea != textViewMargin.DrawingRectangle)
            {
                adjustScrollBars = true;
                textViewMargin.DrawingRectangle = textViewMarginArea;
            }
            if (clipRectangle.IntersectsWith(textViewMarginArea))
            {
                textViewMarginArea.Intersect(clipRectangle);
                if (!textViewMarginArea.IsEmpty)
                {
                    try
                    {
                        textViewMargin.OnPaint(g, textViewMarginArea);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Got exception : " + ex);
                    }
                }
            }

            if (adjustScrollBars)
            {
                try
                {
                    this.motherTextAreaControl.AdjustScrollBars(null, null);
                }
                catch (Exception) {}
            }

            try
            {
                Caret.UpdateCaretPosition();
            }
            catch (Exception) {}

            base.OnPaint(e);
        }