Csharp/C Sharp/2D Graphics/Smooth Paint
HatchBrush Demo
<source lang="csharp"> /* GDI+ Programming in C# and VB .NET by Nick Symmonds Publisher: Apress ISBN: 159059035X
- /
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections; using System.ruponentModel; using System.Windows.Forms; using System.Data; namespace hatch_c {
/// <summary> /// Summary description for hatch. /// </summary> public class hatch : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ruponentModel.Container components = null; public hatch() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // hatch // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "hatch"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "hatch"; this.Load += new System.EventHandler(this.hatch_Load); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new hatch()); } private void hatch_Load(object sender, System.EventArgs e) { } protected override void OnPaint ( PaintEventArgs e ) { HatchBrush h = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Black, Color.Cyan); Pen P = new Pen(h, 20); e.Graphics.Clear(Color.AliceBlue); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawLine(P, 80, 90, 80, 200 ); e.Graphics.FillEllipse(h, 50, 50, 50, 30 ); } }
}
</source>
Smoothing Paint
<source lang="csharp"> /* User Interfaces in C#: Windows Forms and Custom Controls by Matthew MacDonald Publisher: Apress ISBN: 1590590457
- /
using System; using System.Drawing; using System.Collections; using System.ruponentModel; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace GDI_Basics {
/// <summary> /// Summary description for Smoothing. /// </summary> public class Smoothing : System.Windows.Forms.Form { internal System.Windows.Forms.GroupBox grpHighQuality; internal System.Windows.Forms.PictureBox picHighQuality; internal System.Windows.Forms.GroupBox grpAntiAlias; internal System.Windows.Forms.PictureBox picAntialias; internal System.Windows.Forms.GroupBox grpHighSpeed; internal System.Windows.Forms.PictureBox picHighSpeed; internal System.Windows.Forms.GroupBox grpNone; internal System.Windows.Forms.PictureBox picNone; /// <summary> /// Required designer variable. /// </summary> private System.ruponentModel.Container components = null; public Smoothing() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.grpHighQuality = new System.Windows.Forms.GroupBox(); this.picHighQuality = new System.Windows.Forms.PictureBox(); this.grpAntiAlias = new System.Windows.Forms.GroupBox(); this.picAntialias = new System.Windows.Forms.PictureBox(); this.grpHighSpeed = new System.Windows.Forms.GroupBox(); this.picHighSpeed = new System.Windows.Forms.PictureBox(); this.grpNone = new System.Windows.Forms.GroupBox(); this.picNone = new System.Windows.Forms.PictureBox(); this.grpHighQuality.SuspendLayout(); this.grpAntiAlias.SuspendLayout(); this.grpHighSpeed.SuspendLayout(); this.grpNone.SuspendLayout(); this.SuspendLayout(); // // grpHighQuality // this.grpHighQuality.Controls.AddRange(new System.Windows.Forms.Control[] { this.picHighQuality}); this.grpHighQuality.FlatStyle = System.Windows.Forms.FlatStyle.System; this.grpHighQuality.Location = new System.Drawing.Point(12, 276); this.grpHighQuality.Name = "grpHighQuality"; this.grpHighQuality.Size = new System.Drawing.Size(344, 85); this.grpHighQuality.TabIndex = 8; this.grpHighQuality.TabStop = false; this.grpHighQuality.Text = "HighQuality"; // // picHighQuality // this.picHighQuality.Location = new System.Drawing.Point(8, 16); this.picHighQuality.Name = "picHighQuality"; this.picHighQuality.Size = new System.Drawing.Size(328, 64); this.picHighQuality.TabIndex = 0; this.picHighQuality.TabStop = false; this.picHighQuality.Paint += new System.Windows.Forms.PaintEventHandler(this.picHighQuality_Paint); // // grpAntiAlias // this.grpAntiAlias.Controls.AddRange(new System.Windows.Forms.Control[] { this.picAntialias}); this.grpAntiAlias.FlatStyle = System.Windows.Forms.FlatStyle.System; this.grpAntiAlias.Location = new System.Drawing.Point(12, 188); this.grpAntiAlias.Name = "grpAntiAlias"; this.grpAntiAlias.Size = new System.Drawing.Size(344, 85); this.grpAntiAlias.TabIndex = 7; this.grpAntiAlias.TabStop = false; this.grpAntiAlias.Text = "AntiAlias"; // // picAntialias // this.picAntialias.Location = new System.Drawing.Point(8, 16); this.picAntialias.Name = "picAntialias"; this.picAntialias.Size = new System.Drawing.Size(328, 64); this.picAntialias.TabIndex = 0; this.picAntialias.TabStop = false; this.picAntialias.Paint += new System.Windows.Forms.PaintEventHandler(this.picAntialias_Paint); // // grpHighSpeed // this.grpHighSpeed.Controls.AddRange(new System.Windows.Forms.Control[] { this.picHighSpeed}); this.grpHighSpeed.FlatStyle = System.Windows.Forms.FlatStyle.System; this.grpHighSpeed.Location = new System.Drawing.Point(12, 100); this.grpHighSpeed.Name = "grpHighSpeed"; this.grpHighSpeed.Size = new System.Drawing.Size(344, 85); this.grpHighSpeed.TabIndex = 6; this.grpHighSpeed.TabStop = false; this.grpHighSpeed.Text = "HighSpeed"; // // picHighSpeed // this.picHighSpeed.Location = new System.Drawing.Point(8, 16); this.picHighSpeed.Name = "picHighSpeed"; this.picHighSpeed.Size = new System.Drawing.Size(328, 64); this.picHighSpeed.TabIndex = 0; this.picHighSpeed.TabStop = false; this.picHighSpeed.Paint += new System.Windows.Forms.PaintEventHandler(this.picHighSpeed_Paint); // // grpNone // this.grpNone.Controls.AddRange(new System.Windows.Forms.Control[] { this.picNone}); this.grpNone.FlatStyle = System.Windows.Forms.FlatStyle.System; this.grpNone.Location = new System.Drawing.Point(12, 12); this.grpNone.Name = "grpNone"; this.grpNone.Size = new System.Drawing.Size(344, 85); this.grpNone.TabIndex = 5; this.grpNone.TabStop = false; this.grpNone.Text = "None"; // // picNone // this.picNone.Location = new System.Drawing.Point(8, 16); this.picNone.Name = "picNone"; this.picNone.Size = new System.Drawing.Size(328, 64); this.picNone.TabIndex = 0; this.picNone.TabStop = false; this.picNone.Paint += new System.Windows.Forms.PaintEventHandler(this.picNone_Paint); // // Smoothing // this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.ClientSize = new System.Drawing.Size(372, 374); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.grpHighQuality, this.grpAntiAlias, this.grpHighSpeed, this.grpNone}); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.Name = "Smoothing"; this.Text = "Smoothing"; this.grpHighQuality.ResumeLayout(false); this.grpAntiAlias.ResumeLayout(false); this.grpHighSpeed.ResumeLayout(false); this.grpNone.ResumeLayout(false); this.ResumeLayout(false); } #endregion private void picNone_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { DrawEllipse(e.Graphics); } private void picHighSpeed_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; DrawEllipse(e.Graphics); } private void picAntialias_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; DrawEllipse(e.Graphics); } private void picHighQuality_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.HighQuality; DrawEllipse(e.Graphics); } private void DrawEllipse(Graphics g) { Pen drawingPen = new Pen(Color.Red, 5); g.DrawEllipse(drawingPen, 10, 10, 300, 40); } [STAThread] static void Main() { Application.Run(new Smoothing()); } }
}
</source>