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();
}
}
}
}
Imports
GraphicsDLLVB
Public
Class Form1
Inherits System.Windows.Forms.Form
Private _colorShape As
ColorShape
#Region
" Windows Form Designer generated code "
Public Sub
New()
MyBase.New()
'This
call is required by the Windows Form Designer.
InitializeComponent()
_colorShape
= New ColorShape
_colorShape.Color
= Color.Red
_colorShape.Shape
= ColorShape.Shapes.Cross
AddHandler
comboBox1.SelectedIndexChanged, AddressOf
Me.comboBox1_SelectedIndexChanged
AddHandler
comboBox2.SelectedIndexChanged, AddressOf
Me.comboBox2_SelectedIndexChanged
End Sub
'Form overrides dispose to clean up the component
list.
Protected Overloads
Overrides Sub
Dispose(ByVal disposing
As Boolean)
If
disposing Then
If
Not (components Is
Nothing) Then
components.Dispose()
End
If
End
If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents
panel1 As System.Windows.Forms.Panel
Friend WithEvents
comboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents
comboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents
button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()>
Private Sub
InitializeComponent()
Me.panel1
= New System.Windows.Forms.Panel
Me.comboBox2
= New System.Windows.Forms.ComboBox
Me.comboBox1
= New System.Windows.Forms.ComboBox
Me.button1
= New System.Windows.Forms.Button
Me.SuspendLayout()
'
'panel1
'
Me.panel1.Location
= New System.Drawing.Point(10, 38)
Me.panel1.Name
= "panel1"
Me.panel1.Size
= New System.Drawing.Size(144, 144)
Me.panel1.TabIndex
= 7
'
'comboBox2
'
Me.comboBox2.Items.AddRange(New
Object() {"Cross", "Square", "Circle"})
Me.comboBox2.Location
= New System.Drawing.Point(162, 94)
Me.comboBox2.Name
= "comboBox2"
Me.comboBox2.Size
= New System.Drawing.Size(121, 21)
Me.comboBox2.TabIndex
= 6
Me.comboBox2.Text
= "Cross"
'
'comboBox1
'
Me.comboBox1.Items.AddRange(New
Object() {"Red", "Green", "Blue"})
Me.comboBox1.Location
= New System.Drawing.Point(162, 62)
Me.comboBox1.Name
= "comboBox1"
Me.comboBox1.Size
= New System.Drawing.Size(121, 21)
Me.comboBox1.TabIndex
= 5
Me.comboBox1.Text
= "Red"
'
'button1
'
Me.button1.Location
= New System.Drawing.Point(202, 206)
Me.button1.Name
= "button1"
Me.button1.TabIndex
= 4
Me.button1.Text
= "Save"
'
'Form1
'
Me.AutoScaleBaseSize
= New System.Drawing.Size(5, 13)
Me.ClientSize
= New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.panel1)
Me.Controls.Add(Me.comboBox2)
Me.Controls.Add(Me.comboBox1)
Me.Controls.Add(Me.button1)
Me.Name
= "Form1"
Me.Text
= "Form1"
Me.ResumeLayout(False)
End Sub
#End
Region
Private Sub
button1_Click(ByVal sender
As Object,
ByVal e As
System.EventArgs) Handles button1.Click
Dim
dlg As SaveFileDialog =
New SaveFileDialog
dlg.AddExtension = True
dlg.DefaultExt = ".wff"
dlg.Filter = "Well Formed Files (*.wff)|*.wff"
If
dlg.ShowDialog() = DialogResult.OK Then
_colorShape.Save(dlg.FileName)
End
If
End Sub
Private Sub
comboBox1_SelectedIndexChanged(ByVal sender
As Object,
ByVal e As
System.EventArgs)
Select
Case Me.comboBox1.Text
Case
"Red"
Me._colorShape.Color
= Color.Red
Case
"Green"
Me._colorShape.Color
= Color.Green
Case
"Blue"
Me._colorShape.Color
= Color.Blue
End
Select
Me.panel1.Invalidate()
End Sub
Private Sub
comboBox2_SelectedIndexChanged(ByVal sender
As Object,
ByVal e As
System.EventArgs)
Select
Case Me.comboBox2.Text
Case
"Cross"
Me._colorShape.Shape
= ColorShape.Shapes.Cross
Case
"Circle"
Me._colorShape.Shape
= ColorShape.Shapes.Circle
Case
"Square"
Me._colorShape.Shape
= ColorShape.Shapes.Square
End
Select
Me.panel1.Invalidate()
End Sub
Private Sub
panel1_Paint(ByVal sender
As Object,
ByVal e As
System.Windows.Forms.PaintEventArgs) Handles
panel1.Paint
_colorShape.Draw(e.Graphics,
Me.panel1.ClientRectangle)
End Sub
End
Class
The application looks like this when running.
Use your Back button to return to the article.