Smoothing Paint
/*
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.ComponentModel;
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.ComponentModel.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());
}
}
}
Related examples in the same category