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


C# Region.Union方法代碼示例

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


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

示例1: Union_RectF_Example

public void Union_RectF_Example(PaintEventArgs e)
{
             
    // Create the first rectangle and draw it to the screen in black.
    Rectangle regionRect = new Rectangle(20, 20, 100, 100);
    e.Graphics.DrawRectangle(Pens.Black, regionRect);
             
    // create the second rectangle and draw it to the screen in red.
    RectangleF unionRect = new RectangleF(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red,
        Rectangle.Round(unionRect));
             
    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);
             
    // Get the area of union for myRegion when combined with
             
    // complementRect.
    myRegion.Union(unionRect);
             
    // Fill the union area of myRegion with blue.
    SolidBrush myBrush = new SolidBrush(Color.Blue);
    e.Graphics.FillRegion(myBrush, myRegion);
}
開發者ID:.NET開發者,項目名稱:System.Drawing,代碼行數:24,代碼來源:Region.Union

示例2: Form1

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

  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "";
      this.Resize += new System.EventHandler(this.Form1_Resize);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

    }
    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {      
      Graphics g = e.Graphics;
      g.FillRectangle(Brushes.White, this.ClientRectangle);

      Region reg = new Region();
      reg.MakeEmpty();

      GraphicsPath gp = new GraphicsPath();
      gp.AddEllipse(10, 10, 50, 50);
      reg.Union(gp);

      gp.Reset();
      gp.AddLine(40, 40, 70, 10);
      gp.AddLine(70, 10, 140, 140);
      gp.CloseFigure();
      reg.Union(gp);

      reg.Union(new Rectangle(40, 50, 60, 60));

      // Set the clipping region
      g.SetClip(reg, CombineMode.Replace);

      g.FillRectangle(Brushes.Green, this.ClientRectangle);

      gp.Dispose();
      reg.Dispose();
    }

    private void Form1_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }
  }
開發者ID:C#程序員,項目名稱:System.Drawing,代碼行數:64,代碼來源:Region.Union


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