當前位置: 首頁>>代碼示例>>C#>>正文


C# GraphicsPath.AddRectangle方法代碼示例

本文整理匯總了C#中System.Drawing.Drawing2D.GraphicsPath.AddRectangle方法的典型用法代碼示例。如果您正苦於以下問題:C# GraphicsPath.AddRectangle方法的具體用法?C# GraphicsPath.AddRectangle怎麽用?C# GraphicsPath.AddRectangle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Drawing2D.GraphicsPath的用法示例。


在下文中一共展示了GraphicsPath.AddRectangle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddRectangleExample

private void AddRectangleExample(PaintEventArgs e)
{
             
    // Create a GraphicsPath object and add a rectangle to it.
    GraphicsPath myPath = new GraphicsPath();
    Rectangle pathRect = new Rectangle(20, 20, 100, 200);
    myPath.AddRectangle(pathRect);
             
    // Draw the path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}
開發者ID:.NET開發者,項目名稱:System.Drawing.Drawing2D,代碼行數:12,代碼來源:GraphicsPath.AddRectangle

示例2: PathGradient

//引入命名空間
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Drawing2D;  // PathGradientBrush 

namespace PathGradient
{
    public class PathGradient : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components = null;

        public PathGradient()
        {
            this.Text = "PathGradient - CenterPoint";
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(256, 213);
            this.Name = "PathGradient";
            this.Text = "PathGradient";

        }
        static void Main() 
        {
            Application.Run(new PathGradient());
        }
        protected override void OnPaint(PaintEventArgs e)
        {   
            Graphics g = e.Graphics;
            Font f = new Font(new FontFamily("Times New Roman"), 10);
            Brush fb = new SolidBrush(Color.Black);
            GraphicsPath gp;
            PathGradientBrush pGB;  // namespace System.Drawing.Drawing2D;
            Rectangle rec;
            Color cR = Color.Red, cW = Color.White, cY = Color.Yellow;
            int w = 100, h = 70;

            // Left upper rectangle:
            g.DrawString("Center", f, fb, 10, 5);
            gp = new GraphicsPath();
            rec = new Rectangle(10, 20, w, h);
            gp.AddRectangle(rec);
            pGB = new PathGradientBrush(gp);
            pGB.CenterPoint = new Point(10 + w/2, 20 + h/2);
            pGB.CenterColor = cR;
            pGB.SurroundColors = new Color[1]{cW};
            g.FillRectangle(pGB, rec);

            // Right upper rectangle:
            g.DrawString("Center - 2 x 2 Colors", f, fb, w + 20, 5);
            gp = new GraphicsPath();
            rec = new Rectangle(20 + w, 20, w, h);
            gp.AddRectangle(rec);
            pGB = new PathGradientBrush(gp);
            pGB.CenterPoint = new Point(w + 20 + w/2, 20 + h/2);
            pGB.CenterColor = cR;
            pGB.SurroundColors = new Color[4]{cW, cY, cW, cY};
            g.FillRectangle(pGB, rec);

            // Left down rectangle:
            g.DrawString("LefTopCenter", f, fb, 10, h + 25);
            gp = new GraphicsPath();
            rec = new Rectangle(10, h + 40, w, h);
            gp.AddRectangle(rec);
            pGB = new PathGradientBrush(gp);
            pGB.CenterPoint = new Point(10, h + 40);
            pGB.CenterColor = cR;
            pGB.SurroundColors = new Color[1]{cW};
            g.FillRectangle(pGB, rec);

            // Ellipse
            g.DrawString("Top", f, fb, w + 20, h + 25);
            gp = new GraphicsPath();
            rec = new Rectangle(w + 20, h + 40, w, h);
            gp.AddEllipse(rec);
            pGB = new PathGradientBrush(gp);
            pGB.CenterPoint = new Point(w + 20 + w/2, h + 40);
            pGB.CenterColor = cR;
            pGB.SurroundColors = new Color[1]{cW};
            g.FillRectangle(pGB, rec);

            g.Dispose();    
            fb.Dispose();
        }
    }
}
開發者ID:C#程序員,項目名稱:System.Drawing.Drawing2D,代碼行數:89,代碼來源:GraphicsPath.AddRectangle


注:本文中的System.Drawing.Drawing2D.GraphicsPath.AddRectangle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。