Пример #1
0
		//以上全部为一些简单的属性.
		
		//构造函数
		public TextArea(TextEditorControl motherTextEditorControl, TextAreaControl motherTextAreaControl)
		{
			this.motherTextAreaControl      = motherTextAreaControl;
			this.motherTextEditorControl    = motherTextEditorControl;
			
			caret            = new Caret(this);//附加插入符.
			selectionManager = new SelectionManager(Document);//附加选择管理器.
						
			ResizeRedraw = true;
			
			SetStyle(ControlStyles.DoubleBuffer, false);
			SetStyle(ControlStyles.Opaque, false);
			SetStyle(ControlStyles.ResizeRedraw, true);
			SetStyle(ControlStyles.Selectable, true);
			
			textViewMargin = new TextViewMargin(this);//附加主要的文本区域。
			gutterMargin = new GutterMargin(this);//附加装订线区域.
			foldMargin   = new FoldMargin(this);//附加折叠区域.
			iconBarMargin = new IconBarMargin(this);//附加图标栏区域.
			leftMargins.AddRange(new AbstractMargin[] { iconBarMargin, gutterMargin, foldMargin });
			
			OptionsChanged();
			
			textAreaClipboardHandler = new TextAreaClipboardHandler(this);//附加剪切办处理程序.
			new TextAreaMouseHandler(this).Attach();
			new TextAreaDragDropHandler().Attach(this);
			
			bracketshemes.Add(new BracketHighlightingScheme('{', '}'));
			bracketshemes.Add(new BracketHighlightingScheme('(', ')'));
			bracketshemes.Add(new BracketHighlightingScheme('[', ']'));
			
			caret.PositionChanged += new EventHandler(SearchMatchingBracket);
			Document.TextContentChanged += new EventHandler(TextContentChanged);
			Document.FoldingManager.FoldingsChanged += new EventHandler(DocumentFoldingsChanged);
		}
Пример #2
0
        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);
        }