SmoothingMode: AntiAlias


   


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


   


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


   

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


   

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


           
          


HatchBrush Demo


   

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

    }
}

           
          


Scrolling Demo



   

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Scrolling
{
    /// <summary>
    /// Summary description for Scrolling.
    /// </summary>
    public class Scrolling : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Scrolling()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.Text = "Scrolling";
            this.Size = new Size(210, 290);

            //
            // 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()
        {
            // 
            // Scrolling
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(176, 254);
            this.Name = "Scrolling";
            this.Text = "Scrolling";

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Scrolling());
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g;
            g = Graphics.FromHwnd(this.Handle);
            GraphicsUnit units = GraphicsUnit.Pixel;

            string path = "MonetZsu.jpg";
            Image im = Image.FromFile(path);
            this.AutoScrollMinSize = new Size(im.Width, im.Height);
            //this.AutoScroll = true;

            Point P = this.AutoScrollPosition;
            Rectangle dstR = this.ClientRectangle;
            RectangleF srcR = new RectangleF(-P.X, -P.Y, dstR.Width, dstR.Height);
            g.DrawImage(im, dstR, srcR, units);
            g.Dispose();
        }
    }
}


           
          


P18_Scrolling.zip( 19 k)

Draw Pyramid

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Drawing2D;

namespace Pyramid
{
///

/// Summary description for Pyramid.
///

public class Pyramid1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
///

/// Required designer variable.
///

private System.ComponentModel.Container components = null;

int rot = 0;
Point center = new Point(125, 100);
public Pyramid1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

this.Text = “Pyramid by Transfomation”;
//
// TODO: Add any constructor code after InitializeComponent call
//
}

///

/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///

/// Required method for Designer support – do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Name = “button1”;
this.button1.Size = new System.Drawing.Size(48, 24);
this.button1.TabIndex = 0;
this.button1.Text = “Rotate”;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Pyramid
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = “Pyramid”;
this.Text = “Pyramid”;
this.ResumeLayout(false);

}
#endregion

///

/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Pyramid1());
}
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(this.BackColor);

Pyramid(g);
//PyramidPathRotate(g);
g.Dispose();
}
protected void Pyramid(Graphics g)
{
Pen p = new Pen(Color.Blue);
int ten = 10;
Rectangle rc = new Rectangle(50, 90, 150, ten); // the base rectangle
g.DrawRectangle(p, rc);
for(int i = 1;i <= 7; i++) { rc.Offset(0,-ten); rc.Inflate(-ten, 0); g.DrawRectangle(p, rc); } p.Dispose(); } private void button1_Click(object sender, System.EventArgs e) { // rot++; // rot is a class member // PyramidPathRotate(CreateGraphics()); // Refresh(); } protected void PyramidPathRotate(Graphics g) { GraphicsPath gP = new GraphicsPath(); // create an empty path Pen p = new Pen(Color.Blue); int ten = 10; Rectangle rc = new Rectangle(50, 90, 150, ten); // the base rectangle gP.AddRectangle(rc); for(int i = 1;i <= 7; i++) { rc.Offset(0,-ten); rc.Inflate(-ten,0); gP.AddRectangle(rc); } Matrix m = new Matrix(); m.RotateAt(45*rot, center, MatrixOrder.Append); gP.Transform(m); g.DrawPath(p, gP); // draw the rotated path g.FillEllipse(Brushes.Red, center.X, center.Y, 3, 3); // center point p.Dispose(); } } } [/csharp]