当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.ExcludeClip方法代码示例

本文整理汇总了C#中System.Drawing.Graphics.ExcludeClip方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.ExcludeClip方法的具体用法?C# Graphics.ExcludeClip怎么用?C# Graphics.ExcludeClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.ExcludeClip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:29,代码来源:GrayscaleFilter.cs

示例2: Apply

        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            graphics.SmoothingMode = SmoothingMode.None;
            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.None;
            int halfWidth = rect.Width / 2;
            int halfHeight = rect.Height / 2;
            int newWidth = rect.Width / magnificationFactor;
            int newHeight = rect.Height / magnificationFactor;
            Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight);
            graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel);
            graphics.Restore(state);
        }
开发者ID:BallisticLingonberries,项目名称:ShareX,代码行数:28,代码来源:MagnifierFilter.cs

示例3: Apply

		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}
			GraphicsState state = graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
				Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
				for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++) {
					for (int x = fastBitmap.Left; x < fastBitmap.Right; x++) {
						Color color = fastBitmap.GetColorAt(x, y);
						color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
						fastBitmap.SetColorAt(x, y, color);
					}
				}
				fastBitmap.DrawTo(graphics, applyRect.Location);
			}
			graphics.Restore(state);
		}
开发者ID:logtcn,项目名称:greenshot,代码行数:32,代码来源:HighlightFilter.cs

示例4: Apply

 public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
 {
     int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
     double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
     Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
     if (applyRect.Width == 0 || applyRect.Height == 0)
     {
         return;
     }
     GraphicsState state = graphics.Save();
     if (Invert)
     {
         graphics.SetClip(applyRect);
         graphics.ExcludeClip(rect);
     }
     if (GDIplus.IsBlurPossible(blurRadius))
     {
         GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
     }
     else
     {
         using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect))
         {
             ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius);
             fastBitmap.DrawTo(graphics, applyRect);
         }
     }
     graphics.Restore(state);
     return;
 }
开发者ID:Edison6351,项目名称:ShareX,代码行数:30,代码来源:BlurFilter.cs

示例5: Draw

        protected override void Draw(Graphics g)
        {
            regionFillPath = new GraphicsPath();

            for (int i = 0; i < nodes.Count - 1; i++)
            {
                regionFillPath.AddLine(nodes[i].Position, nodes[i + 1].Position);
            }

            if (nodes.Count > 2)
            {
                regionFillPath.CloseFigure();

                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                g.DrawRectangleProper(borderPen, currentArea);
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }

            if (nodes.Count > 1)
            {
                g.DrawPath(borderPen, regionFillPath);
            }

            base.Draw(g);
        }
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:34,代码来源:PolygonRegion.cs

示例6: ExcludeClipRectangle

        public void ExcludeClipRectangle(Graphics g)
        {
            // Create rectangle for exclusion.
            Rectangle excludeRect = new Rectangle(100, 100, 200, 200);

            // Set clipping region to exclude rectangle.
            g.ExcludeClip(excludeRect);

            var myBrush = new SolidBrush(Color.FromArgb(127, 0x66, 0xEF, 0x7F));

            // Fill large rectangle to show clipping region.
            g.FillRectangle(myBrush, 0, 0, 500, 500);
        }
开发者ID:mono,项目名称:sysdrawing-coregraphics,代码行数:13,代码来源:DrawingView.cs

示例7: Apply

		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}

			GraphicsState state =  graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS);
			using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) {
				graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
			}
			graphics.Restore(state);
		}
开发者ID:logtcn,项目名称:greenshot,代码行数:26,代码来源:BrightnessFilter.cs

示例8: Paint

        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            this.checkBox.Size = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal);
            this.checkBox.Location = new Point(2, cellBounds.Height / 2 - this.checkBox.Height / 2);
            this.checkRectangle.Size = new Size(this.checkBox.Right + 1, clipBounds.Height);

            Point realLocation = this.checkBox.Location + (Size)cellBounds.Location;
            ButtonState state = GetCheckBoxState();

            Padding newPadding = cellStyle.Padding;
            newPadding.Left = checkRectangle.Width;
            cellStyle.Padding = newPadding;

            GraphicsState gstate = graphics.Save();
            graphics.ExcludeClip(new Rectangle(realLocation, this.checkBox.Size));
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            graphics.Restore(gstate);

            CheckBoxRenderer.DrawCheckBox(graphics, realLocation, ConvertFromButtonState(state, false, this.mouseInCheckBox));
        }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:20,代码来源:DatagridViewCheckBoxHeaderCell.cs

示例9: Draw

        protected override void Draw(Graphics g)
        {
            if (points.Count > 2)
            {
                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                g.DrawPath(borderPen, regionFillPath);
                g.DrawLine(borderPen, points[0], points[points.Count - 1]);
                g.DrawRectangleProper(borderPen, currentArea);
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }

            base.Draw(g);
        }
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:22,代码来源:FreeHandRegion.cs

示例10: OnDraw

        public override void OnDraw(Graphics g)
        {
            if (Rectangle.Width > 10 && Rectangle.Height > 10)
            {
                GraphicsPath gpTail = null;

                if (TailVisible)
                {
                    gpTail = CreateTailPath();
                }

                if (FillColor.A > 0)
                {
                    using (Brush brush = new SolidBrush(FillColor))
                    {
                        g.FillRectangle(brush, Rectangle);
                    }
                }

                if (gpTail != null)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;

                    if (FillColor.A > 0)
                    {
                        g.ExcludeClip(Rectangle);

                        using (Brush brush = new SolidBrush(FillColor))
                        {
                            g.FillPath(brush, gpTail);
                        }

                        g.ResetClip();
                    }

                    if (BorderSize > 0 && BorderColor.A > 0)
                    {
                        g.ExcludeClip(Rectangle.Offset(-1));

                        using (Pen pen = new Pen(BorderColor, BorderSize))
                        {
                            g.DrawPath(pen, gpTail);
                        }

                        g.ResetClip();
                    }

                    g.SmoothingMode = SmoothingMode.None;
                }

                if (BorderSize > 0 && BorderColor.A > 0)
                {
                    if (gpTail != null)
                    {
                        using (Region region = new Region(gpTail))
                        {
                            g.ExcludeClip(region);
                        }
                    }

                    Rectangle rect = Rectangle.Offset(BorderSize - 1);

                    using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
                    {
                        g.DrawRectangleProper(pen, rect);
                    }

                    g.ResetClip();
                }

                if (gpTail != null)
                {
                    gpTail.Dispose();
                }

                DrawText(g);
            }
        }
开发者ID:ElectronicWar,项目名称:ShareX,代码行数:78,代码来源:SpeechBalloonDrawingShape.cs

示例11: DrawItem

        void DrawItem(Graphics g, int index, Rectangle itemRect, bool hot, bool pressed, Rectangle targetRect, OutlookBarBand drawingBand)
        {
            OutlookBarBand band = bands[currentBandIndex];
            if (drawingBand != null)
                band = drawingBand;

            Point pt = new Point(0, 0);
            // Set clip region so that we don't draw outside the viewport
            Rectangle viewPortRect = GetViewPortRect();
            if (targetRect != Rectangle.Empty)
                viewPortRect = targetRect;

            using (Region clippingRegion = new Region(viewPortRect))
            {
                g.Clip = clippingRegion;
                // Clip the arrow buttons
                g.ExcludeClip(downArrowRect);
                g.ExcludeClip(upArrowRect);

                Color textColor = band.TextColor;
                Color backColor = band.Background;
                Color highLight = band.Background;

                if (ColorUtil.UsingCustomColor)
                {
                    backColor = ColorUtil.VSNetControlColor;
                    highLight = ColorUtil.VSNetControlColor;
                }

                if (hot)
                {
                    backColor = ColorUtil.VSNetSelectionColor;
                    highLight = ColorUtil.VSNetBorderColor;
                }

                if (pressed)
                    backColor = ColorUtil.VSNetPressedColor;

                //john hatton jdh
                if (band.Items[index].Selected)
                    highLight = Color.Blue;

                if (band.IconView == IconView.Large && band.LargeImageList != null)
                {
                    Size largeImageSize = band.LargeImageList.ImageSize;
                    pt.X = itemRect.Left + (viewPortRect.Width - largeImageSize.Width) / 2;
                    pt.Y = itemRect.Top;

                    Rectangle iconRect = new Rectangle(pt, largeImageSize);
                    using (Brush b = new SolidBrush(backColor))
                    {
                        iconRect.Inflate(2, 2);
                        if (backgroundBitmap != null)
                        {
                            g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel);
                            // If we have a background bitmap, draw the item background
                            // only during the hot state
                            if (hot)
                            {
                                g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                    iconRect.Width, iconRect.Height);
                            }
                        }
                        else
                        {

                            // If we don't have a background, always draw the
                            // item backgound
                            g.FillRectangle(b, iconRect.Left, iconRect.Top,
                                iconRect.Width, iconRect.Height);
                        }

                        using (Pen p = new Pen(highLight))
                        {
                            if (backgroundBitmap == null || hot == true)
                            {
                                g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1);
                            }

                        }
                    }

                    // I dont' use the image list to do the drawing because cliping does not work
                    if (band.Items[index].ImageIndex != -1 && band.LargeImageList != null)
                    {
                        // Only if we have a valid image index
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.DrawImage(band.LargeImageList.Images[band.Items[index].ImageIndex], pt);
                        g.SmoothingMode = SmoothingMode.Default;
                    }

                    // Draw the label
                    int top = itemRect.Top + largeImageSize.Height + Y_LARGEICON_LABEL_OFFSET;
                    Size textSize = GetLabelSize(g, band, index);
                    int left = itemRect.Left + (viewPortRect.Width - textSize.Width) / 2;
                    using (Brush b = new SolidBrush(textColor))
                    {
                        g.DrawString(band.Items[index].Text, Font, b, new Point(left, top));
                    }

//.........这里部分代码省略.........
开发者ID:sillsdev,项目名称:CarlaLegacy,代码行数:101,代码来源:OutlookBar.cs

示例12: DrawDropShadow

 internal static void DrawDropShadow(Graphics graphics, Rectangle shadowSourceRectangle, Color baseColor, int shadowDepth, LightSourcePosition lightSourcePosition, float lightSourceIntensity, bool roundEdges)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if ((shadowSourceRectangle.IsEmpty || (shadowSourceRectangle.Width < 0)) || (shadowSourceRectangle.Height < 0))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidShadowRectangle"), "shadowRectangle");
     }
     if ((shadowDepth < 1) || (shadowDepth > 12))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidShadowDepth"), "shadowDepth");
     }
     if ((lightSourceIntensity <= 0f) || (lightSourceIntensity > 1f))
     {
         throw new ArgumentException(SR.GetString("Error_InvalidLightSource"), "lightSourceIntensity");
     }
     Rectangle rectangle = shadowSourceRectangle;
     Size empty = Size.Empty;
     if ((lightSourcePosition & LightSourcePosition.Center) > 0)
     {
         rectangle.Inflate(shadowDepth, shadowDepth);
     }
     if ((lightSourcePosition & LightSourcePosition.Left) > 0)
     {
         empty.Width += shadowDepth + 1;
     }
     else if ((lightSourcePosition & LightSourcePosition.Right) > 0)
     {
         empty.Width -= shadowDepth + 1;
     }
     if ((lightSourcePosition & LightSourcePosition.Top) > 0)
     {
         empty.Height += shadowDepth + 1;
     }
     else if ((lightSourcePosition & LightSourcePosition.Bottom) > 0)
     {
         empty.Height -= shadowDepth + 1;
     }
     rectangle.Offset(empty.Width, empty.Height);
     GraphicsContainer container = graphics.BeginContainer();
     GraphicsPath path = new GraphicsPath();
     if (roundEdges)
     {
         path.AddPath(GetRoundedRectanglePath(shadowSourceRectangle, 8), true);
     }
     else
     {
         path.AddRectangle(shadowSourceRectangle);
     }
     try
     {
         using (Region region = new Region(path))
         {
             graphics.SmoothingMode = SmoothingMode.AntiAlias;
             graphics.ExcludeClip(region);
             Color color = Color.FromArgb(Convert.ToInt32((float) (40f * lightSourceIntensity)), baseColor);
             int num = Math.Max(40 / shadowDepth, 2);
             for (int i = 0; i < shadowDepth; i++)
             {
                 rectangle.Inflate(-1, -1);
                 using (Brush brush = new SolidBrush(color))
                 {
                     using (GraphicsPath path2 = new GraphicsPath())
                     {
                         if (roundEdges)
                         {
                             path2.AddPath(GetRoundedRectanglePath(rectangle, 8), true);
                         }
                         else
                         {
                             path2.AddRectangle(rectangle);
                         }
                         graphics.FillPath(brush, path2);
                     }
                 }
                 color = Color.FromArgb(color.A + num, color.R, color.G, color.B);
             }
         }
     }
     finally
     {
         graphics.EndContainer(container);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:86,代码来源:ActivityDesignerPaint.cs

示例13: Draw

        protected override void Draw(Graphics g)
        {
            List<Rectangle> areas = AreaManager.GetValidAreas;

            if (areas.Count > 0 || !AreaManager.CurrentHoverArea.IsEmpty)
            {
                UpdateRegionPath();

                using (Region region = new Region(regionFillPath))
                {
                    g.ExcludeClip(region);
                    g.FillRectangle(shadowBrush, 0, 0, Width, Height);
                    g.ResetClip();
                }

                /*foreach (WindowInfo wi in AreaManager.Windows)
                {
                    g.DrawRectangleProper(Pens.Yellow, Rectangle.Intersect(ScreenRectangle0Based, wi.Rectangle0Based));
                }*/

                borderDotPen.DashOffset = (float)timer.Elapsed.TotalSeconds * 10;
                borderDotPen2.DashOffset = 5 + (float)timer.Elapsed.TotalSeconds * 10;

                g.DrawPath(borderPen, regionDrawPath);

                if (areas.Count > 1)
                {
                    Rectangle totalArea = AreaManager.CombineAreas();
                    g.DrawCrossRectangle(borderPen, totalArea, 15);
                    CaptureHelpers.DrawTextWithOutline(g, string.Format("X:{0}, Y:{1}, Width:{2}, Height:{3}", totalArea.X, totalArea.Y,
                        totalArea.Width, totalArea.Height), new PointF(totalArea.X + 5, totalArea.Y - 20), textFont, Color.White, Color.Black);
                }

                if (AreaManager.IsCurrentHoverAreaValid)
                {
                    GraphicsPath hoverFillPath = new GraphicsPath() { FillMode = FillMode.Winding };
                    AddShapePath(hoverFillPath, AreaManager.CurrentHoverArea);

                    g.FillPath(lightBrush, hoverFillPath);

                    GraphicsPath hoverDrawPath = new GraphicsPath() { FillMode = FillMode.Winding };
                    AddShapePath(hoverDrawPath, AreaManager.CurrentHoverArea.SizeOffset(-1));

                    g.DrawPath(borderDotPen, hoverDrawPath);
                    g.DrawPath(borderDotPen2, hoverDrawPath);
                }

                if (AreaManager.IsCurrentAreaValid)
                {
                    g.DrawRectangleProper(borderDotPen, AreaManager.CurrentArea);
                    g.DrawRectangleProper(borderDotPen2, AreaManager.CurrentArea);
                    g.ExcludeClip(AreaManager.CurrentArea);
                    DrawObjects(g);
                    g.ResetClip();
                }

                foreach (Rectangle area in areas)
                {
                    if (area.Width > 100 && area.Height > 20)
                    {
                        g.Clip = new Region(area);

                        CaptureHelpers.DrawTextWithOutline(g, string.Format("X:{0}, Y:{1}, Width:{2}, Height:{3}", area.X, area.Y, area.Width, area.Height),
                            new PointF(area.X + 5, area.Y + 5), textFont, Color.White, Color.Black);
                    }
                }
            }
            else
            {
                g.FillRectangle(shadowBrush, 0, 0, Width, Height);
            }
        }
开发者ID:modulexcite,项目名称:ZScreen_Google_Code,代码行数:72,代码来源:RectangleRegion.cs

示例14: DrawSelectionFrame

 public static void DrawSelectionFrame(Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect, Color backColor)
 {
     Brush activeBrush;
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (active)
     {
         activeBrush = GetActiveBrush(backColor);
     }
     else
     {
         activeBrush = GetSelectedBrush(backColor);
     }
     Region clip = graphics.Clip;
     graphics.ExcludeClip(insideRect);
     graphics.FillRectangle(activeBrush, outsideRect);
     graphics.Clip = clip;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:ControlPaint.cs

示例15: Draw

        // Render the treeview starting from startingLine
        internal void Draw(Graphics g, TreeNodeEx startNode)
        {
            if (updating > 0)
            {
                return;
            }

            Rectangle clientRectangle = ClientRectangle;
            int drawableHeight = clientRectangle.Height;
            int drawableWidth = clientRectangle.Width - xOffset;

            // We count the visible rows to see if we need the v scrollbar but we wait before deciding if we need the h scroll bar.
            bool needsHScrollBar = false;
            bool needsVScrollBar = GetNeedVScrollBar() && scrollable;
            bool createNewVScrollBar = false;
            bool createNewHScrollBar = false;

            if (needsVScrollBar)
            {
                // Don't allow drawing on the area that is going to be the scroll bar.
                // Create the scroll bar so we can get its width.
                if (vScrollBar == null)
                {
                    vScrollBar = new Forms.VScrollBar();
                    createNewVScrollBar = true;
                }
                drawableWidth -= vScrollBar.Width;
                Rectangle rect = new Rectangle(drawableWidth + xOffset, 0, vScrollBar.Width, clientRectangle.Height);
                g.ExcludeClip(rect);
            }
            else
            {
                // Check to see if the top node is not the first node and we have room for the whole tree.
                // If so, abandon the draw and redraw the whole tree from the top.
                if (topNode != null && topNode != this.nodes[0])
                {
                    topNode = null;
                    Invalidate();
                    return;
                }
                if (vScrollBar != null)
                {
                    // We don't need the scroll bar anymore.
                    Controls.Remove(vScrollBar);
                    vScrollBar.Dispose();
                    vScrollBar = null;
                }
            }
            // Is the node being processed on the screen.
            bool drawing = false;
            // Start counting from the top.
            int nodeFromTop = -1;
            // Number of nodes.
            int nodeCount = 0;
            int topNodePosition = 0;
            // The maximum width of a displayed node.
            float maxWidth = 0;
            //StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
            if (topNode == null && this.nodes.Count > 0)
            {
                topNode = this.nodes[0];
            }
            RectangleF textBounds = Rectangle.Empty;

            NodeEnumeratorEx nodes = new NodeEnumeratorEx(this.nodes);
            using (Pen markerPen = new Pen(SystemColors.ControlDarkDark))
            {
                markerPen.DashStyle = DashStyle.Dot;
                while (nodes.MoveNext())
                {
                    // If we havnt started drawing yet, then see if we need to and if so clear the background.
                    if (!drawing)
                    {
                        if (nodes.currentNode  == topNode)
                        {
                            // We are at the top node.
                            nodeFromTop = 0;
                            topNodePosition = nodeCount;
                        }

                        // Check to see if we must start drawing. Clear the background.
                        if (nodeFromTop >= 0 && (nodes.currentNode == startNode || startNode == root))
                        {
                            // Clear background.
                            int y = ItemHeight * nodeFromTop;
                            using (SolidBrush b = new SolidBrush(BackColor))
                            {
                                g.FillRectangle(b, 0, y, ClientSize.Width, ClientSize.Height - y);
                            }
                            drawing = true;
                        }
                    }

                    // Even if we arnt drawing nodes yet, we need to measure if the nodes are visible, for hscrollbar purposes.
                    if (nodeFromTop >= 0 && drawableHeight > 0)
                    {
                        textBounds = GetTextBounds(g, nodes.currentNode, nodeFromTop, nodes.level);
                        // Is the text too wide to fit in - if so we need an h scroll bar.
                        if (textBounds.Right > drawableWidth && !needsHScrollBar && scrollable)
//.........这里部分代码省略.........
开发者ID:RubisetCie,项目名称:box2c,代码行数:101,代码来源:TreeViewEx.cs


注:本文中的System.Drawing.Graphics.ExcludeClip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。