GUI Windows Form C#

/*
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 Peaks
{
    /// 
    /// Summary description for Peaks.
    /// 

    public class Peaks : System.Windows.Forms.Form
    {
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.RadioButton radioButton1;
        private System.Windows.Forms.RadioButton radioButton2;
        private System.Windows.Forms.RadioButton radioButton3;
        private System.Windows.Forms.RadioButton radioButton4;
        private System.Windows.Forms.RadioButton radioButton5;
        private System.Windows.Forms.RadioButton radioButton6;
        private System.Windows.Forms.RadioButton radioButton7;
        private System.Windows.Forms.RadioButton radioButton8;
        private System.Windows.Forms.RadioButton radioButton9;
        private System.Windows.Forms.RadioButton radioButton10;
        private System.Windows.Forms.RadioButton radioButton11;
        private System.Windows.Forms.RadioButton radioButton12;
        Point[] pnts = { new Point(20, 90), new Point(55, 70),
                           new Point(80, 80), new Point(105, 40),  
                           new Point(130, 90)};
        /// 
        /// Required designer variable.
        /// 

        private System.ComponentModel.Container components = null;
        public Peaks()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.radioButton1.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton2.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton3.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton4.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton5.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton6.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton7.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton8.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton9.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton10.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton11.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            this.radioButton12.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
            //
            // 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.groupBox1 = new System.Windows.Forms.GroupBox();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.radioButton6 = new System.Windows.Forms.RadioButton();
            this.radioButton5 = new System.Windows.Forms.RadioButton();
            this.radioButton4 = new System.Windows.Forms.RadioButton();
            this.radioButton7 = new System.Windows.Forms.RadioButton();
            this.radioButton9 = new System.Windows.Forms.RadioButton();
            this.radioButton8 = new System.Windows.Forms.RadioButton();
            this.radioButton10 = new System.Windows.Forms.RadioButton();
            this.radioButton12 = new System.Windows.Forms.RadioButton();
            this.radioButton11 = new System.Windows.Forms.RadioButton();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.radioButton1,
                                                                                    this.radioButton2,
                                                                                    this.radioButton3,
                                                                                    this.radioButton6,
                                                                                    this.radioButton5,
                                                                                    this.radioButton4,
                                                                                    this.radioButton7,
                                                                                    this.radioButton9,
                                                                                    this.radioButton8,
                                                                                    this.radioButton10,
                                                                                    this.radioButton12,
                                                                                    this.radioButton11});
            this.groupBox1.Location = new System.Drawing.Point(200, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(304, 120);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Primitives";
            // 
            // radioButton1
            // 
            this.radioButton1.Location = new System.Drawing.Point(16, 24);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new System.Drawing.Size(88, 16);
            this.radioButton1.TabIndex = 0;
            this.radioButton1.Text = "4xLine";
            // 
            // radioButton2
            // 
            this.radioButton2.Location = new System.Drawing.Point(112, 24);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new System.Drawing.Size(56, 16);
            this.radioButton2.TabIndex = 0;
            this.radioButton2.Text = "Lines";
            // 
            // radioButton3
            // 
            this.radioButton3.Location = new System.Drawing.Point(184, 24);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.Size = new System.Drawing.Size(80, 16);
            this.radioButton3.TabIndex = 0;
            this.radioButton3.Text = "Polygon";
            // 
            // radioButton6
            // 
            this.radioButton6.Location = new System.Drawing.Point(184, 48);
            this.radioButton6.Name = "radioButton6";
            this.radioButton6.Size = new System.Drawing.Size(80, 16);
            this.radioButton6.TabIndex = 0;
            this.radioButton6.Text = "Curve 1.1";
            // 
            // radioButton5
            // 
            this.radioButton5.Location = new System.Drawing.Point(112, 48);
            this.radioButton5.Name = "radioButton5";
            this.radioButton5.Size = new System.Drawing.Size(88, 16);
            this.radioButton5.TabIndex = 0;
            this.radioButton5.Text = "Curve 0.6";
            // 
            // radioButton4
            // 
            this.radioButton4.Location = new System.Drawing.Point(16, 48);
            this.radioButton4.Name = "radioButton4";
            this.radioButton4.Size = new System.Drawing.Size(88, 16);
            this.radioButton4.TabIndex = 0;
            this.radioButton4.Text = "Curve 0";
            // 
            // radioButton7
            // 
            this.radioButton7.Location = new System.Drawing.Point(16, 72);
            this.radioButton7.Name = "radioButton7";
            this.radioButton7.Size = new System.Drawing.Size(88, 16);
            this.radioButton7.TabIndex = 0;
            this.radioButton7.Text = "2xBezier";
            // 
            // radioButton9
            // 
            this.radioButton9.Location = new System.Drawing.Point(184, 72);
            this.radioButton9.Name = "radioButton9";
            this.radioButton9.Size = new System.Drawing.Size(112, 16);
            this.radioButton9.TabIndex = 0;
            this.radioButton9.Text = "ClosedCurve 1.1";
            // 
            // radioButton8
            // 
            this.radioButton8.Location = new System.Drawing.Point(112, 72);
            this.radioButton8.Name = "radioButton8";
            this.radioButton8.Size = new System.Drawing.Size(88, 16);
            this.radioButton8.TabIndex = 0;
            this.radioButton8.Text = "Beziers";
            // 
            // radioButton10
            // 
            this.radioButton10.Location = new System.Drawing.Point(16, 96);
            this.radioButton10.Name = "radioButton10";
            this.radioButton10.Size = new System.Drawing.Size(88, 16);
            this.radioButton10.TabIndex = 0;
            this.radioButton10.Text = "2xBezier";
            // 
            // radioButton12
            // 
            this.radioButton12.Location = new System.Drawing.Point(184, 96);
            this.radioButton12.Name = "radioButton12";
            this.radioButton12.Size = new System.Drawing.Size(88, 16);
            this.radioButton12.TabIndex = 0;
            this.radioButton12.Text = "Curve";
            // 
            // radioButton11
            // 
            this.radioButton11.Location = new System.Drawing.Point(112, 96);
            this.radioButton11.Name = "radioButton11";
            this.radioButton11.Size = new System.Drawing.Size(88, 16);
            this.radioButton11.TabIndex = 0;
            this.radioButton11.Text = "Beziers";
            // 
            // Peaks
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(504, 133);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.groupBox1});
            this.Name = "Peaks";
            this.Text = "Two Peaks";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
        }
        #endregion
        /// 
        /// The main entry point for the application.
        /// 

        [STAThread]
        static void Main() 
        {
            Application.Run(new Peaks());
        }
        private void RBs_CheckedChanged(object sender, System.EventArgs e)
        {
            this.Refresh();
        }
        protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;   
            g.Clear(this.BackColor); 
         
            if (this.radioButton1.Checked) Ex01_4xLine(g);
            if (this.radioButton2.Checked) Ex02_Lines(g);
            if (this.radioButton3.Checked) Ex03_Polygon(g);
            if (this.radioButton4.Checked) Ex04_Curve0(g);
            if (this.radioButton5.Checked) Ex05_Curve1(g);
            if (this.radioButton6.Checked) Ex06_Curve2(g);
            if (this.radioButton7.Checked) Ex07_2xBezier(g);
            if (this.radioButton8.Checked) Ex08_Beziers(g);
            if (this.radioButton9.Checked) Ex09_ClosedCurve(g);
            if (this.radioButton10.Checked) Ex10_2xBezier_2(g);
            if (this.radioButton11.Checked) Ex11_Beziers_2(g);
            if (this.radioButton12.Checked) Ex11_Curve_2(g);
            
            g.Dispose();
        }
        protected void Ex01_4xLine(Graphics g) 
        {
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawLine(pn, 20, 90, 55, 70); 
            g.DrawLine(pn, 55, 70, 80, 80); 
            g.DrawLine(pn, 80, 80,105, 40);
            g.DrawLine(pn,105, 40,130, 90);
        }
        protected void Ex02_Lines(Graphics g) 
        {
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawLines(pn, pnts);
        }
        protected void Ex03_Polygon(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawPolygon(pn, pnts);
        }
        protected void Ex04_Curve0(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawCurve(pn, pnts, 0.0f);
        }
        protected void Ex05_Curve1(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawCurve(pn, pnts, 0.6f);
        }
        protected void Ex06_Curve2(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawCurve(pn, pnts, 1.1f);
        }
        protected void Ex07_2xBezier(Graphics g) 
        {
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80); 
            g.DrawBezier(pn, 80, 80,100, 40,110, 40,130, 90);
        }
        protected void Ex08_Beziers(Graphics g) 
        {
            Pen pn = new Pen(Color.Blue, 2);
            Point[] pnts = {new Point(20, 90), new Point(50, 70),
                               new Point(60, 70), new Point(80, 80),
                               new Point(100, 40), new Point(110, 40),
                               new Point(130, 90)}; 
            g.DrawBeziers(pn, pnts);
        }
        protected void Ex09_ClosedCurve(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            Point[] pnts = {new Point( 20, 90), new Point( 55, 70),
                               new Point( 80, 80), new Point(105, 40),  
                               new Point(130, 90)};
            g.DrawClosedCurve(pn, pnts, 1.1f, System.Drawing.Drawing2D.FillMode.Winding);
        }
        protected void Ex10_2xBezier_2(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            g.DrawBezier(pn, 20, 90, 50, 70, 60, 70, 80, 80); 
            g.DrawBezier(pn, 80, 80,100,120,110,120,130, 90);
        }
        protected void Ex11_Beziers_2(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            int[,] xy = {   { 20, 90}, { 50, 70},
                            { 60, 70}, { 80, 80},
                            {100,120}, {110,120},
                            {130, 90}}; 
            int ii = xy.GetLength(0);
            Point[] pnts = new Point[ii];
            for(int i = 0; i < ii; i++)
            {               
                pnts[i].X = xy[i, 0];
                pnts[i].Y = xy[i, 1];
            }
            g.DrawBeziers(pn, pnts);
        }
        protected void Ex11_Curve_2(Graphics g) 
        {  
            Pen pn = new Pen(Color.Blue, 2);
            Point[] pnts = {new Point( 20, 90), new Point( 55, 70),
                               new Point( 80, 80), new Point(105,120),  
                               new Point(130, 90)};
            g.DrawCurve(pn, pnts, 0.0f);
        }
    }
}