.
In Depth Banner
Skip Navigation Links

Select your preferred language

Host application for the GraphicsDLL and the Shell Extension article.

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

 

using WellFormed;

 

namespace HostApplication

{

  /// <summary>

  /// Summary description for Form1.

  /// </summary>

  public class Form1 : System.Windows.Forms.Form

  {

    private System.Windows.Forms.Button button1;

    private System.Windows.Forms.ComboBox comboBox1;

    private System.Windows.Forms.ComboBox comboBox2;

    private System.Windows.Forms.Panel panel1;

    /// <summary>

    /// Required designer variable.

    /// </summary>

    private System.ComponentModel.Container components = null;

 

    WellFormed.ColorShape _colorShape=new ColorShape();

 

    public Form1()

    {

      //

      // Required for Windows Form Designer support

      //

      InitializeComponent();

 

      _colorShape.Color=Color.Red;

      _colorShape.Shape=ColorShape.Shapes.Cross;

 

      this.comboBox1.SelectedIndexChanged+=new EventHandler(comboBox1_SelectedIndexChanged);

      this.comboBox2.SelectedIndexChanged+=new EventHandler(comboBox2_SelectedIndexChanged);

    }

 

    /// <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.button1 = new System.Windows.Forms.Button();

      this.comboBox1 = new System.Windows.Forms.ComboBox();

      this.comboBox2 = new System.Windows.Forms.ComboBox();

      this.panel1 = new System.Windows.Forms.Panel();

      this.SuspendLayout();

      //

      // button1

      //

      this.button1.Location = new System.Drawing.Point(200, 192);

      this.button1.Name = "button1";

      this.button1.TabIndex = 0;

      this.button1.Text = "Save";

      this.button1.Click += new System.EventHandler(this.button1_Click);

      //

      // comboBox1

      //

      this.comboBox1.Items.AddRange(new object[] {

                               "Red",

                               "Green",

                               "Blue"});

      this.comboBox1.Location = new System.Drawing.Point(160, 48);

      this.comboBox1.Name = "comboBox1";

      this.comboBox1.Size = new System.Drawing.Size(121, 21);

      this.comboBox1.TabIndex = 1;

      this.comboBox1.Text = "Red";

      //

      // comboBox2

      //

      this.comboBox2.Items.AddRange(new object[] {

                               "Cross",

                               "Square",

                               "Circle"});

      this.comboBox2.Location = new System.Drawing.Point(160, 80);

      this.comboBox2.Name = "comboBox2";

      this.comboBox2.Size = new System.Drawing.Size(121, 21);

      this.comboBox2.TabIndex = 2;

      this.comboBox2.Text = "Cross";

      //

      // panel1

      //

      this.panel1.Location = new System.Drawing.Point(8, 24);

      this.panel1.Name = "panel1";

      this.panel1.Size = new System.Drawing.Size(144, 144);

      this.panel1.TabIndex = 3;

      this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);

      //

      // Form1

      //

      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

      this.ClientSize = new System.Drawing.Size(292, 266);

      this.Controls.Add(this.panel1);

      this.Controls.Add(this.comboBox2);

      this.Controls.Add(this.comboBox1);

      this.Controls.Add(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 Form1());

    }

 

    private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

    {

      _colorShape.Draw(e.Graphics,this.panel1.ClientRectangle);

    }

 

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

      switch(this.comboBox1.Text)

      {

        case "Red":

          _colorShape.Color=Color.Red;

          break;

        case "Green":

          _colorShape.Color=Color.Green;

          break;

        case "Blue":

          _colorShape.Color=Color.Blue;

          break;

      }

      this.panel1.Invalidate();

    }

 

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)

    {

      switch(this.comboBox2.Text)

      {

        case "Cross":

          _colorShape.Shape=ColorShape.Shapes.Cross;

          break;

        case "Circle":

          _colorShape.Shape=ColorShape.Shapes.Circle;

          break;

        case "Square":

          _colorShape.Shape=ColorShape.Shapes.Square;

          break;

      }

      this.panel1.Invalidate();

    }

 

    private void button1_Click(object sender, System.EventArgs e)

    {

      SaveFileDialog dlg=new SaveFileDialog();

      dlg.AddExtension=true;

      dlg.DefaultExt=".wff";

      dlg.Filter="Well Formed Files (*.wff)|*.wff";

      if(dlg.ShowDialog()==DialogResult.OK)

      {

        _colorShape.Save(dlg.FileName);

      }

    }

 

    private void button2_Click(object sender, System.EventArgs e)

    {

      OpenFileDialog dlg=new OpenFileDialog();

      dlg.Filter="Well Formed Files (*.wff)|*.wff";

      if(dlg.ShowDialog()==DialogResult.OK)

      {

        this._colorShape=ColorShape.Load(dlg.FileName);

        this.panel1.Invalidate();

      }

    }

  }

}

 

The application looks like this when running.

 

Use your Back button to return to the article.

Copyright © Bob Powell 2000-.  All rights reserved.