Form for data input

image_pdfimage_print


   

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

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

namespace Employee
{
  /// <summary>
  /// Summary description for Form1.
  /// </summary>
  public class EmployeeForm1 : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ListBox listBox1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public EmployeeForm1()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected 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.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.listBox1 = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // button1
      // 
      this.button1.Location = new System.Drawing.Point(48, 240);
      this.button1.Name = "button1";
      this.button1.Size = new System.Drawing.Size(80, 24);
      this.button1.TabIndex = 2;
      this.button1.Text = "Add Item";
      this.button1.Click += new System.EventHandler(this.button1_Click);
      // 
      // button2
      // 
      this.button2.Location = new System.Drawing.Point(160, 240);
      this.button2.Name = "button2";
      this.button2.Size = new System.Drawing.Size(96, 24);
      this.button2.TabIndex = 3;
      this.button2.Text = "Cancel";
      this.button2.Click += new System.EventHandler(this.button2_Click);
      // 
      // listBox1
      // 
      this.listBox1.Location = new System.Drawing.Point(38, 32);
      this.listBox1.Name = "listBox1";
      this.listBox1.Size = new System.Drawing.Size(216, 186);
      this.listBox1.TabIndex = 0;
      this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_OnDoubleClick);
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.listBox1,
                                      this.button2,
                                      this.button1});
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new EmployeeForm1());
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      EMPLOYEE emp = new EMPLOYEE();
      EmpForm eform = new EmpForm (emp);
      if (eform.ShowDialog (this) == DialogResult.Cancel)
        return;
      eform.GetEmployeeData (out emp);
      listBox1.Items.Add (emp);
    }

    private void button2_Click(object sender, System.EventArgs e)
    {
      Application.Exit ();
    }

    private void listBox1_OnDoubleClick(object sender, System.EventArgs e)
    {
      int index = listBox1.SelectedIndex;
      if (index < 0)
        return;
      EMPLOYEE emp = (EMPLOYEE) listBox1.Items&#91;index&#93;;
      EmpForm eform = new EmpForm (emp);
      if (eform.ShowDialog (this) == DialogResult.Cancel)
        return;
      eform.GetEmployeeData (out emp);
      listBox1.Items.RemoveAt (index);
      listBox1.Items.Insert (index,emp);
    }
  }
  public struct EMPLOYEE
  {
    public string  FirstName;
    public string  LastName;
    public string  Address;
    public string  City;
    public string  State;
    public string  Zip;
    public override string ToString ()
    {
      return (LastName + ", " + FirstName);
    }
  }
  /// <summary>
  /// Summary description for EmpForm.
  /// </summary>
  public class EmpForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.TextBox textBox3;
    private System.Windows.Forms.TextBox textBox4;
    private System.Windows.Forms.TextBox textBox5;
    private System.Windows.Forms.TextBox textBox6;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public EmpForm(EMPLOYEE emp)
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      textBox1.Text = emp.FirstName;
      textBox2.Text = emp.LastName;
      textBox3.Text = emp.Address;
      textBox4.Text = emp.City;
      textBox5.Text = emp.State;
      textBox6.Text = emp.Zip;
    }

    /// <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.textBox4 = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.label3 = new System.Windows.Forms.Label();
      this.textBox5 = new System.Windows.Forms.TextBox();
      this.button1 = new System.Windows.Forms.Button();
      this.button2 = new System.Windows.Forms.Button();
      this.label5 = new System.Windows.Forms.Label();
      this.label6 = new System.Windows.Forms.Label();
      this.textBox2 = new System.Windows.Forms.TextBox();
      this.textBox3 = new System.Windows.Forms.TextBox();
      this.label4 = new System.Windows.Forms.Label();
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.textBox6 = new System.Windows.Forms.TextBox();
      this.SuspendLayout();
      // 
      // textBox4
      // 
      this.textBox4.Location = new System.Drawing.Point(16, 182);
      this.textBox4.Name = "textBox4";
      this.textBox4.Size = new System.Drawing.Size(120, 20);
      this.textBox4.TabIndex = 3;
      this.textBox4.Text = "";
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(16, 16);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(136, 16);
      this.label1.TabIndex = 8;
      this.label1.Text = "First Name";
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(16, 64);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(128, 16);
      this.label2.TabIndex = 9;
      this.label2.Text = "Last Name";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(16, 109);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(120, 19);
      this.label3.TabIndex = 10;
      this.label3.Text = "Address";
      // 
      // textBox5
      // 
      this.textBox5.Location = new System.Drawing.Point(168, 184);
      this.textBox5.Name = "textBox5";
      this.textBox5.Size = new System.Drawing.Size(32, 20);
      this.textBox5.TabIndex = 4;
      this.textBox5.Text = "";
      // 
      // button1
      // 
      this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
      this.button1.Location = new System.Drawing.Point(48, 224);
      this.button1.Name = "button1";
      this.button1.TabIndex = 6;
      this.button1.Text = "OK";
      this.button1.Click += new System.EventHandler(this.button1_Click);
      // 
      // button2
      // 
      this.button2.CausesValidation = false;
      this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
      this.button2.Location = new System.Drawing.Point(160, 224);
      this.button2.Name = "button2";
      this.button2.TabIndex = 7;
      this.button2.Text = "Cancel";
      // 
      // label5
      // 
      this.label5.Location = new System.Drawing.Point(168, 163);
      this.label5.Name = "label5";
      this.label5.Size = new System.Drawing.Size(40, 16);
      this.label5.TabIndex = 12;
      this.label5.Text = "State";
      // 
      // label6
      // 
      this.label6.Location = new System.Drawing.Point(224, 163);
      this.label6.Name = "label6";
      this.label6.Size = new System.Drawing.Size(48, 16);
      this.label6.TabIndex = 13;
      this.label6.Text = "Zip";
      // 
      // textBox2
      // 
      this.textBox2.Location = new System.Drawing.Point(16, 82);
      this.textBox2.Name = "textBox2";
      this.textBox2.Size = new System.Drawing.Size(208, 20);
      this.textBox2.TabIndex = 1;
      this.textBox2.Text = "";
      // 
      // textBox3
      // 
      this.textBox3.Location = new System.Drawing.Point(16, 132);
      this.textBox3.Name = "textBox3";
      this.textBox3.Size = new System.Drawing.Size(208, 20);
      this.textBox3.TabIndex = 2;
      this.textBox3.Text = "";
      // 
      // label4
      // 
      this.label4.Location = new System.Drawing.Point(16, 163);
      this.label4.Name = "label4";
      this.label4.Size = new System.Drawing.Size(120, 16);
      this.label4.TabIndex = 11;
      this.label4.Text = "City";
      // 
      // textBox1
      // 
      this.textBox1.Location = new System.Drawing.Point(16, 32);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(160, 20);
      this.textBox1.TabIndex = 0;
      this.textBox1.Text = "";
      // 
      // textBox6
      // 
      this.textBox6.Location = new System.Drawing.Point(224, 184);
      this.textBox6.Name = "textBox6";
      this.textBox6.Size = new System.Drawing.Size(48, 20);
      this.textBox6.TabIndex = 5;
      this.textBox6.Text = "";
      // 
      // EmpForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.CancelButton = this.button2;
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.button2,
                                      this.button1,
                                      this.label6,
                                      this.label5,
                                      this.label4,
                                      this.label3,
                                      this.label2,
                                      this.label1,
                                      this.textBox6,
                                      this.textBox5,
                                      this.textBox4,
                                      this.textBox3,
                                      this.textBox2,
                                      this.textBox1});
      this.MinimizeBox = false;
      this.Name = "EmpForm";
      this.ShowInTaskbar = false;
      this.Text = "EmpForm";
      this.ResumeLayout(false);

    }
    #endregion

    public void GetEmployeeData (out EMPLOYEE emp)
    {
      emp.FirstName = textBox1.Text;
      emp.LastName = textBox2.Text;
      emp.Address = textBox3.Text;
      emp.City = textBox4.Text;
      emp.State = textBox5.Text;
      emp.Zip = textBox6.Text;
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
      this.Close ();
    }
  }
  
}


           
          


Change the background and text colors of a form using Color Dialog

image_pdfimage_print


   


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


   public class ShowColorsComplex : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Button backgroundColorButton;
      private System.Windows.Forms.Button textColorButton;

      public ShowColorsComplex()
      {
         InitializeComponent();
      }

      private void InitializeComponent()
      {
         this.backgroundColorButton = new System.Windows.Forms.Button();
         this.textColorButton = new System.Windows.Forms.Button();
         this.SuspendLayout();
         // 
         // backgroundColorButton
         // 
         this.backgroundColorButton.Location = new System.Drawing.Point(16, 16);
         this.backgroundColorButton.Name = "backgroundColorButton";
         this.backgroundColorButton.Size = new System.Drawing.Size(264, 32);
         this.backgroundColorButton.TabIndex = 0;
         this.backgroundColorButton.Text = "Change Background Color";
         this.backgroundColorButton.Click += new System.EventHandler(this.backgroundColorButton_Click);
         // 
         // textColorButton
         // 
         this.textColorButton.Location = new System.Drawing.Point(16, 64);
         this.textColorButton.Name = "textColorButton";
         this.textColorButton.Size = new System.Drawing.Size(264, 32);
         this.textColorButton.TabIndex = 1;
         this.textColorButton.Text = "Change Text Color";
         this.textColorButton.Click += new System.EventHandler(this.textColorButton_Click);
         // 
         // ShowColorsComplex
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 109);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.textColorButton,
                                                                      this.backgroundColorButton});
         this.Name = "ShowColorsComplex";
         this.Text = "ShowColorsComplex";
         this.ResumeLayout(false);

      }
      static void Main() 
      {
         Application.Run( new ShowColorsComplex() );
      }

      private void textColorButton_Click(object sender, System.EventArgs e ){
         ColorDialog colorChooser = new ColorDialog();
         DialogResult result;

         result = colorChooser.ShowDialog();

         if ( result == DialogResult.Cancel )
            return;
         
         backgroundColorButton.ForeColor = colorChooser.Color;
         textColorButton.ForeColor = colorChooser.Color;

      }
      private void backgroundColorButton_Click(object sender, System.EventArgs e ){
         ColorDialog colorChooser = new ColorDialog();
         DialogResult result;

         colorChooser.FullOpen = true;
         result = colorChooser.ShowDialog();

         if ( result == DialogResult.Cancel )
            return;
         this.BackColor = colorChooser.Color;
      }
   }



           
          


Draw image based on the window size

image_pdfimage_print


   


  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;
  using System.Drawing.Imaging;

  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "";
      this.Resize += new System.EventHandler(this.Form1_Resize);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

    }
    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {      
      Graphics g = e.Graphics;
      Bitmap bmp = new Bitmap("winter.jpg");

      Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
      g.DrawImage(bmp, this.ClientRectangle);
    }

    private void Form1_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }
  }


           
          


Auto scroll form window

image_pdfimage_print


   

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

  public class Form1 : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Label label1;
    private System.ComponentModel.Container components;
  
    public Form1()
    {
      InitializeComponent();
    }

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

    private void InitializeComponent()
    {
      this.label1 = new System.Windows.Forms.Label();
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F);
      this.label1.Location = new System.Drawing.Point(16, 16);
      this.label1.Size = new System.Drawing.Size(376, 224);
      this.label1.TabIndex = 0;
      this.label1.Text = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text ";
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.AutoScroll = true;
      this.AutoScrollMinSize = new System.Drawing.Size(300, 300);
      this.ClientSize = new System.Drawing.Size(403, 256);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.label1});
      this.Text = "Form1";

    }

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



           
          


Set Form window title and center the Form window on the desktop

image_pdfimage_print


   


using System;
using System.Windows.Forms;
using System.Drawing;

public class TestForm2 {
  static void Main() {
    Form simpleForm = new Form();

    simpleForm.Height = 200;
    simpleForm.Width = 200;

    simpleForm.Text = "This is the title";

    // Center the Form on the desktop
    simpleForm.StartPosition = FormStartPosition.CenterScreen;
    simpleForm.Visible = true;

    Application.Run(simpleForm);
  }
}

           
          


Assign Form window default value

image_pdfimage_print


   

using System;
using System.Drawing;
using System.Windows.Forms;
public class EnterPrice : Form {
  private Button enter = new Button();
  private Label answer = new Label();
  private TextBox text = new TextBox( );

  public EnterPrice( ) {
    enter.Text = "Enter Price";
    text.Text = "";
    answer.Text = "";

    Size = new Size(300,200);
    answer.Size = new Size(200,50);

    enter.Location = new Point(30 + enter.Width, 30);
    text.Location = new Point (40 + enter.Width + enter.Width, 30);
    answer.Location = new Point(20, 60);

    AcceptButton = enter;

    Controls.Add(text);
    Controls.Add(answer);
    Controls.Add(enter);

    enter.Click += new EventHandler(Enter_Click);
  }

  protected void Enter_Click(Object sender, EventArgs e) {
    try{
    Console.WriteLine(Double.Parse(text.Text));
    }catch(Exception){
    }
    text.Text = "";
    text.Focus();
  }
  static void Main() {
    Application.Run(new EnterPrice());
  }
}

           
          


Create Graphics Object from form window handle

image_pdfimage_print


   


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

public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.CheckBox checkBox1;
    private System.Windows.Forms.CheckBox checkBox2;
    private System.Windows.Forms.CheckBox checkBox3;
    private System.Windows.Forms.RadioButton radioButton1;
    private System.Windows.Forms.RadioButton radioButton2;
    private System.Windows.Forms.RadioButton radioButton3;
    private System.Windows.Forms.Button button1;

    private System.ComponentModel.Container components = null;

    public Form1() {
      InitializeComponent();
    }

    private void InitializeComponent() {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.checkBox2 = new System.Windows.Forms.CheckBox();
            this.checkBox3 = new System.Windows.Forms.CheckBox();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.radioButton3 = new System.Windows.Forms.RadioButton();
            this.button1 = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.radioButton1,
                                                                                    this.radioButton2,
                                                                                    this.radioButton3});
            this.groupBox1.Location = new System.Drawing.Point(8, 120);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(120, 144);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Color";
            this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
            // 
            // checkBox1
            // 
            this.checkBox1.Location = new System.Drawing.Point(8, 8);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.TabIndex = 1;
            this.checkBox1.Text = "Circle";
            // 
            // checkBox2
            // 
            this.checkBox2.Location = new System.Drawing.Point(8, 40);
            this.checkBox2.Name = "checkBox2";
            this.checkBox2.TabIndex = 2;
            this.checkBox2.Text = "Rectangle";
            // 
            // checkBox3
            // 
            this.checkBox3.Location = new System.Drawing.Point(8, 72);
            this.checkBox3.Name = "checkBox3";
            this.checkBox3.TabIndex = 3;
            this.checkBox3.Text = "String";
            // 
            // radioButton1
            // 
            this.radioButton1.Location = new System.Drawing.Point(8, 32);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.TabIndex = 4;
            this.radioButton1.Text = "Red";
            this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
            // 
            // radioButton2
            // 
            this.radioButton2.Location = new System.Drawing.Point(8, 64);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.TabIndex = 5;
            this.radioButton2.Text = "Green";
            // 
            // radioButton3
            // 
            this.radioButton3.Location = new System.Drawing.Point(8, 96);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.TabIndex = 6;
            this.radioButton3.Text = "Blue";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(8, 280);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(112, 32);
            this.button1.TabIndex = 4;
            this.button1.Text = "Draw";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(408, 317);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.button1,
                                                                          this.checkBox3,
                                                                          this.checkBox2,
                                                                          this.checkBox1,
                                                                          this.groupBox1});
            this.Name = "Form1";
            this.Text = "CheckBox and RadioButton Sample";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

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

        private void groupBox1_Enter(object sender, System.EventArgs e)
        {
           Console.WriteLine("group box enter event");
        }

        private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
        {
           Console.WriteLine("Radio Button checked changed event");
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            Graphics g = Graphics.FromHwnd(this.Handle);
            String str = "";
            Rectangle rc = new Rectangle(150, 50, 250, 250);
            
            if(radioButton1.Checked)
            {
                str = "red";
            }
            if(radioButton2.Checked)
            {
                str+="Green";
            }
            if(radioButton3.Checked)
            {
                str+="Blue";
            }

            if (checkBox1.Checked)
            {
                str+="Ellipse";
            }
            if (checkBox2.Checked)
            {
                str += "Rectangle";
            }
            if (checkBox3.Checked)
            {
                g.FillRectangle(new SolidBrush(Color.White), rc);
                g.DrawString(str, new Font("Verdana", 12), new SolidBrush(Color.Black), rc);
            }
            

        }
    }