new SolidBrush(ForeColor)

image_pdfimage_print
   
 
using System;
using System.Drawing;
using System.Windows.Forms;
   
class HelloCenteredMeasured: Form
{
     public static void Main() 
     {
          Application.Run(new HelloCenteredMeasured()); 
     }
     public HelloCenteredMeasured()
     {
          Text = "Hello Centered Using MeasureString";
          BackColor = SystemColors.Window;
          ForeColor = SystemColors.WindowText;
          ResizeRedraw = true;
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics graphics      = pea.Graphics;
          string   str       = "Hello, world!";
          SizeF    sizefText = graphics.MeasureString(str, Font);
   
          graphics.DrawString(str, Font, new SolidBrush(ForeColor), 
                          (ClientSize.Width  - sizefText.Width)  / 2, 
                          (ClientSize.Height - sizefText.Height) / 2);
     }
}

    


Solid Brush: Firebrick

image_pdfimage_print


   
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class MainForm : Form {
    public static void Main() {
        Application.Run(new MainForm());
    }

    protected void OnPaint(object sender, PaintEventArgs e) {
        Graphics g = e.Graphics;
        SolidBrush blueBrush = new SolidBrush(Color.Blue);
        SolidBrush pen2 = (SolidBrush)Brushes.Firebrick;
        g.FillEllipse(blueBrush, 10, 10, 100, 100);
        g.FillPie(Brushes.Black, 150, 10, 120, 150, 90, 80);
        SolidBrush brush3 = new SolidBrush(Color.Purple);
        g.FillPolygon(brush3,
            new Point[]{ new Point(30, 140),
                new Point(265, 200), new Point(100, 225),
                new Point(190, 190), new Point(50, 330),
                new Point(20, 180)});
        Rectangle r = new Rectangle(150, 10, 130, 60);
        g.FillRectangle(Brushes.Blue, r);
        g.DrawString("Hello out there...How are ya?", new Font("Arial", 12), Brushes.White, r);
    }
}

    


SmoothingMode: HighQuality

image_pdfimage_print


   


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
    private System.Windows.Forms.PictureBox picNone;

      public Form1() {
            InitializeComponent();
      }
    private void picNone_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
        
      Pen drawingPen = new Pen(Color.Red, 5);
      e.Graphics.DrawEllipse(drawingPen, 10, 10, 300, 40);
    }

    private void InitializeComponent()
    {
      this.picNone = new System.Windows.Forms.PictureBox();
      this.SuspendLayout();
      // 
      // 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.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(392, 382);
      this.Controls.Add(this.picNone);
      this.Name = "Smoothing";
      this.Text = "Smoothing";
      this.ResumeLayout(false);

    }

      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }

}


           
          


SmoothingMode: AntiAlias

image_pdfimage_print


   


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
    private System.Windows.Forms.PictureBox picNone;

      public Form1() {
            InitializeComponent();
      }
    private void picNone_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        
      Pen drawingPen = new Pen(Color.Red, 5);
      e.Graphics.DrawEllipse(drawingPen, 10, 10, 300, 40);
    }

    private void InitializeComponent()
    {
      this.picNone = new System.Windows.Forms.PictureBox();
      this.SuspendLayout();
      // 
      // 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.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(392, 382);
      this.Controls.Add(this.picNone);
      this.Name = "Smoothing";
      this.Text = "Smoothing";
      this.ResumeLayout(false);

    }

      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }

}


           
          


SmoothingMode: HighSpeed

image_pdfimage_print


   


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
    private System.Windows.Forms.PictureBox picNone;

      public Form1() {
            InitializeComponent();
      }
    private void picNone_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
        
      Pen drawingPen = new Pen(Color.Red, 5);
      e.Graphics.DrawEllipse(drawingPen, 10, 10, 300, 40);
    }

    private void InitializeComponent()
    {
      this.picNone = new System.Windows.Forms.PictureBox();
      this.SuspendLayout();
      // 
      // 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.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(392, 382);
      this.Controls.Add(this.picNone);
      this.Name = "Smoothing";
      this.Text = "Smoothing";
      this.ResumeLayout(false);

    }

      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }

}


           
          


No Smoothing Mode

image_pdfimage_print


   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
    private System.Windows.Forms.PictureBox picNone;

      public Form1() {
            InitializeComponent();
      }
    private void picNone_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Pen drawingPen = new Pen(Color.Red, 5);
      e.Graphics.DrawEllipse(drawingPen, 10, 10, 300, 40);
    }

    private void InitializeComponent()
    {
      this.picNone = new System.Windows.Forms.PictureBox();
      this.SuspendLayout();
      // 
      // 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.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(392, 382);
      this.Controls.Add(this.picNone);
      this.Name = "Smoothing";
      this.Text = "Smoothing";
      this.ResumeLayout(false);

    }

      [STAThread]
      static void Main()
      {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
      }

}



           
          


Smoothing Paint

image_pdfimage_print


   

/*
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());
        }
    }
}