Csharp/C Sharp/2D Graphics/Line Join — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:41, 26 мая 2010

All Line Join

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;
public class Form1 : Form
{
      public Form1() {
            InitializeComponent();
            
      }
    private void SimpleStyleRenderer_Paint(object sender, PaintEventArgs e)
    {
      e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
      Pen myPen = new Pen(Color.Blue, 10);
      int y = 20;
      foreach (LineJoin join in Enum.GetValues(typeof(LineJoin)))
      {
        myPen.LineJoin = join;
        e.Graphics.DrawRectangle(myPen, 20, y, 70, 40);
        e.Graphics.DrawString(join.ToString(), new Font("Tahoma", 8), Brushes.Black, 100, y + 10);
        y += 70;
      }
    }

    private void InitializeComponent()
    {
      this.SuspendLayout();
      // 
      // SimpleStyleRenderer
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(384, 353);
      this.Name = "SimpleStyleRenderer";
      this.Text = "SimpleStyleRenderer";
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.SimpleStyleRenderer_Paint);
      this.ResumeLayout(false);
    }
      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }
}


Line Joins: Miter, Bevel, Round, MiterClipped

 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
   
class LineJoins: Form
{
     public static void Main()
     {
          Application.Run(new LineJoins());
     }
     public LineJoins()
     {
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }       
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          Pen     penNarrow = new Pen(clr);
          Pen     penWide   = new Pen(Color.Gray, cx / 16);
          Point[] apt       = { new Point(1 * cx / 32, 1 * cy / 8), 
                                new Point(4 * cx / 32, 6 * cy / 8),
                                new Point(7 * cx / 32, 1 * cy / 8) };
   
          for (int i = 0; i < 4; i++)
          {
               penWide.LineJoin = (LineJoin) i;
   
               grfx.DrawLines(penWide, apt);
               grfx.DrawLines(penNarrow, apt);
               grfx.TranslateTransform(cx / 4, 0);
          }
     }
}


Line Join style: Bevel

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  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 = "Pen Cap App";
      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.SmoothingMode = SmoothingMode.AntiAlias;
      g.FillRectangle(Brushes.White, this.ClientRectangle);
      Pen p = new Pen(Color.Black, 10);
      p.LineJoin = LineJoin.Bevel;
      e.Graphics.DrawRectangle(p, 20, 20, 200, 200);
      p.Dispose();
    }
    private void Form1_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }
  }