ImageList for ToolBar

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

class SimpleToolBar: Form
{
public static void Main()
{
Application.Run(new SimpleToolBar());
}
public SimpleToolBar()
{
Menu = new MainMenu();
Menu.MenuItems.Add(“File”);
Menu.MenuItems.Add(“Edit”);
Menu.MenuItems.Add(“View”);
Menu.MenuItems.Add(“Help”);

Bitmap bm = new Bitmap(GetType(),”SimpleToolBar.bmp”);

ImageList imglst = new ImageList();
imglst.Images.AddStrip(bm);
imglst.TransparentColor = Color.Cyan;

ToolBar tbar = new ToolBar();
tbar.Parent = this;
tbar.ImageList = imglst;
tbar.ShowToolTips = true;

string[] astr = {“New”, “Open”, “Save”, “Print”, “Cut”, “Copy”, “Paste” };

for (int i = 0; i < 7; i++) { ToolBarButton tbarbtn = new ToolBarButton(); tbarbtn.ImageIndex = i; tbarbtn.ToolTipText = astr[i]; tbar.Buttons.Add(tbarbtn); } } } [/csharp]

GUI and timer


   

/*
C# Programming Tips &amp; 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 Clock
{
  /// <summary>
  /// Summary description for ClockForm.
  /// </summary>
  public class ClockForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.Label label2;
    private System.ComponentModel.IContainer components;

    #region ClockForm Constructor
    public ClockForm()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
      // The following line sets the text for the label box.
      // To display no text, simply use two quote marks.
      label1.Text = "";
      // The following two statements set the text size and
      // cause the time to appear centered in the label box
      label1.Font = new System.Drawing.Font
        ("Microsoft Sans Serif", 24);
      label1.TextAlign = ContentAlignment.MiddleCenter;
      label2.Font = label1.Font;
      label2.TextAlign = ContentAlignment.MiddleCenter;
      // This.Text is the text that will appear in the form&#039;s
      // title bar.
//      this.Text = "My Clock";
      // The following three lines set the timer to tick
      // every second (1000 milliseconds), start the timer and
      // write the initial time to the label box
      timer1.Interval = 1000;
      timer1.Start ();
      SetClock ();
    }
    #endregion
    /// <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.components = new System.ComponentModel.Container();
      this.timer1 = new System.Windows.Forms.Timer(this.components);
      this.label1 = new System.Windows.Forms.Label();
      this.label2 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // timer1
      // 
      this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label1.Location = new System.Drawing.Point(24, 56);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(248, 48);
      this.label1.TabIndex = 0;
      this.label1.Text = "label1";
      // 
      // label2
      // 
      this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label2.Location = new System.Drawing.Point(24, 136);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(248, 48);
      this.label2.TabIndex = 1;
      this.label2.Text = "label2";
      // 
      // ClockForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
      this.ClientSize = new System.Drawing.Size(292, 272);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.label2,
                                      this.label1});
      this.Name = "ClockForm";
      this.Text = "ClockForm";
      this.ResumeLayout(false);

    }
    #endregion

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

    private void timer1_Tick(object sender, System.EventArgs e)
    {
      SetClock ();
    }
    protected void SetClock ()
    {
      string str = DateTime.Now.ToString();
      int index = str.IndexOf (" ");
      label1.Text = str.Substring (index + 1);
      label2.Text = str.Substring (0, index);
    }
  }
}


           
          


Thread and UI Demo

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

public struct MyData {
public double pi;
public int iters;
}
public class Calc {
private double _pi;
private int _iters;

private readonly int TotalIters;
public Calc(int it) {
_iters = 1;
_pi = 0;
TotalIters = it;
}
public MyData PI {
get {
MyData pi = new MyData();
lock (this) {
pi.pi = _pi;
pi.iters = _iters;
}
return pi;
}
}
public Thread MakeThread() {
return new Thread(new ThreadStart(this.ThreadStarter));
}
private void calculate() {
double series = 0;
do {
series ++;
lock (this) {
_iters += 4;
_pi = series * 4;
}
} while (_iters < TotalIters); } private void ThreadStarter() { try { calculate(); } catch (ThreadAbortException e) { Console.WriteLine("ThreadAbortException"); } } } public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox PiValue; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox Iteratons; private Calc pi = new Calc(100000000); private Thread calcThread = null; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Button StopButton; private System.Windows.Forms.Button Pause; private System.ComponentModel.IContainer components; public Form1() { this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.Pause = new System.Windows.Forms.Button(); this.PiValue = new System.Windows.Forms.TextBox(); this.StopButton = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.Iteratons = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(8, 24); this.label1.Name = "label1"; this.label1.TabIndex = 0; this.label1.Text = "Value of PI:"; // // label2 // this.label2.Location = new System.Drawing.Point(8, 72); this.label2.Name = "label2"; this.label2.TabIndex = 2; this.label2.Text = "Iterations:"; // // Pause // this.Pause.Location = new System.Drawing.Point(24, 112); this.Pause.Name = "Pause"; this.Pause.TabIndex = 5; this.Pause.Text = "Pause"; this.Pause.Click += new System.EventHandler(this.Pause_Click); // // PiValue // this.PiValue.Location = new System.Drawing.Point(128, 24); this.PiValue.Name = "PiValue"; this.PiValue.ReadOnly = true; this.PiValue.Size = new System.Drawing.Size(136, 20); this.PiValue.TabIndex = 1; this.PiValue.Text = ""; // // StopButton // this.StopButton.Location = new System.Drawing.Point(200, 112); this.StopButton.Name = "StopButton"; this.StopButton.TabIndex = 4; this.StopButton.Text = "Stop"; this.StopButton.Click += new System.EventHandler(this.StopButton_Click); // this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // this.Iteratons.Location = new System.Drawing.Point(128, 72); this.Iteratons.Name = "Iteratons"; this.Iteratons.ReadOnly = true; this.Iteratons.TabIndex = 3; this.Iteratons.Text = ""; // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 149); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.Pause, this.StopButton, this.Iteratons, this.label2, this.PiValue, this.label1}); this.Load += new System.EventHandler(this.Form1_Load); this.Closed += new System.EventHandler(this.Form1_Closed); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { calcThread = pi.MakeThread(); calcThread.Priority = ThreadPriority.Lowest; calcThread.Start(); } private void timer1_Tick(object sender, System.EventArgs e) { if (this.Pause.Text == "Pause") { MyData p = pi.PI; this.PiValue.Text = p.pi.ToString(); this.Iteratons.Text = p.iters.ToString(); } if (calcThread.IsAlive == false) { StopButton.Enabled = false; Pause.Enabled = false; timer1.Enabled = false; calcThread = null; } } private void StopButton_Click(object sender, System.EventArgs e) { StopButton.Enabled = false; Pause.Enabled = false; timer1.Enabled = false; calcThread.Abort(); calcThread.Join(); calcThread = null; } private void Pause_Click(object sender, System.EventArgs e) { if (this.Pause.Text == "Pause") { calcThread.Suspend(); this.Pause.Text = "Resume"; this.StopButton.Enabled = false; } else { calcThread.Resume(); this.Pause.Text = "Pause"; this.StopButton.Enabled = true; } } private void Form1_Closed(object sender, System.EventArgs e) { if (calcThread != null) { calcThread.Abort(); calcThread.Join(); } } } [/csharp]

Starting and stopping a thread.

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

public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label NumThreads;
private System.Windows.Forms.Label Counter;
private int fCounter;
private ArrayList fThreadList;

private System.ComponentModel.Container components = null;

public Form1() {
InitializeComponent();
fThreadList = new ArrayList();
}

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

for (int i = 0; i < fThreadList.Count; ++i) { Thread fThread = (Thread)fThreadList[i]; fThread.Abort(); } } } base.Dispose(disposing); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.NumThreads = new System.Windows.Forms.Label(); this.Counter = new System.Windows.Forms.Label(); this.SuspendLayout(); this.button1.Location = new System.Drawing.Point(32, 104); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "&Start"; this.button1.Click += new System.EventHandler(this.button1_Click); this.button2.Location = new System.Drawing.Point(136, 104); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(88, 24); this.button2.TabIndex = 1; this.button2.Text = "&Stop"; this.button2.Click += new System.EventHandler(this.button2_Click); this.label1.Location = new System.Drawing.Point(32, 40); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(152, 16); this.label1.TabIndex = 2; this.label1.Text = "Number of Threads Running:"; this.label2.Location = new System.Drawing.Point(32, 64); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(100, 16); this.label2.TabIndex = 3; this.label2.Text = "Counter:"; this.NumThreads.Location = new System.Drawing.Point(192, 40); this.NumThreads.Name = "NumThreads"; this.NumThreads.Size = new System.Drawing.Size(64, 16); this.NumThreads.TabIndex = 4; this.Counter.Location = new System.Drawing.Point(192, 64); this.Counter.Name = "Counter"; this.Counter.Size = new System.Drawing.Size(64, 16); this.Counter.TabIndex = 5; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(272, 165); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.Counter, this.NumThreads, this.label2, this.label1, this.button2, this.button1}); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Form1()); } protected void ThreadFunc() { Boolean done = false; while (!done) { Thread.Sleep(1000); fCounter++; this.Counter.Text = fCounter.ToString(); } } private void button1_Click(object sender, System.EventArgs e) { Thread fThread = new Thread(new ThreadStart(ThreadFunc)); fThread.Start(); fThreadList.Add(fThread); this.NumThreads.Text = fThreadList.Count.ToString(); } private void button2_Click(object sender, System.EventArgs e) { Thread fThread = (Thread)fThreadList[fThreadList.Count - 1]; fThread.Abort(); fThreadList.Remove(fThread); this.NumThreads.Text = fThreadList.Count.ToString(); } } [/csharp]

Background processing in a thread.

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

public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label ValueLabel;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;
private Thread fThread;
private int fValue;

public Form1() {

fValue = 0;
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.ValueLabel = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.Text = “Value of Data:”;
this.button1.Location = new System.Drawing.Point(232, 32);
this.button1.Text = “&Update”;
this.button1.Click += new
System.EventHandler(this.button1_Click);
this.ValueLabel.Location = new System.Drawing.Point(120, 32);
this.button2.Location = new System.Drawing.Point(104, 88);
this.button2.Name = “button2”;
this.button2.RightToLeft =
System.Windows.Forms.RightToLeft.No;
this.button2.Size = new System.Drawing.Size(96, 23);
this.button2.Text = “Start Thread”;
this.button2.Click += new
System.EventHandler(this.button2_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 141);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.ValueLabel,
this.button1,
this.label1});
this.ResumeLayout(false);

}

[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void ThreadProc() {
while (fValue < 1000) { Thread.Sleep(1000); fValue++; } } private void button2_Click(object sender, System.EventArgs e) { fThread = new Thread(new ThreadStart(ThreadProc)); fThread.IsBackground = true; fThread.Start(); } private void button1_Click(object sender, System.EventArgs e) { this.ValueLabel.Text = fValue.ToString(); } } [/csharp]

Talking to a visual element in a background thread.

   
 


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

public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.ProgressBar progressBar1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private Thread fThread = null;
    private System.ComponentModel.Container components = null;

    public Form1() {
        this.progressBar1 = new System.Windows.Forms.ProgressBar();
        this.button1 = new System.Windows.Forms.Button();
        this.button2 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        this.progressBar1.Location = new System.Drawing.Point(24, 32);
        this.progressBar1.Name = "progressBar1";
        this.progressBar1.Size = new System.Drawing.Size(264, 23);
        this.progressBar1.TabIndex = 0;
        this.button1.Location = new System.Drawing.Point(24, 80);
        this.button1.Size = new System.Drawing.Size(136, 40);
        this.button1.Text = "Start Thread";
        this.button1.Click += new
             System.EventHandler(this.button1_Click);
        this.button2.Location = new System.Drawing.Point(168, 80);
        this.button2.Size = new System.Drawing.Size(120, 40);
        this.button2.Text = "Stop Thread";
        this.button2.Click += new
             System.EventHandler(this.button2_Click);
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(704, 429);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
          this.button2,
          this.button1,
          this.progressBar1});

        this.ResumeLayout(false);
    }

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

    }

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

    private void UpdateProgress() {
        if (progressBar1.Value == progressBar1.Maximum) {
            progressBar1.Value = progressBar1.Minimum;
        }
        progressBar1.PerformStep();
    }


    public void ThreadProc() {

        try {
            MethodInvoker mi = new MethodInvoker(this.UpdateProgress);
            while (true) {
                this.BeginInvoke(mi);
                Thread.Sleep(500);
            }
        } catch (ThreadInterruptedException e) {
            Console.WriteLine(
              "Interruption Exception in Thread: {0}",
                  e);
        } catch (Exception we) {
            Console.WriteLine("Exception in Thread: {0}", we);
        }
    }

    private void button1_Click(object sender, System.EventArgs e) {
        fThread = new Thread(new ThreadStart(ThreadProc));
        fThread.IsBackground = true;
        fThread.Start();
    }

    private void button2_Click(object sender, System.EventArgs e) {
        fThread.Interrupt();
        fThread = null;
    }
}

    


Simple Editor based on TextBox

   
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

public class SimpleEditorForm : Form {
    private string filename = "Untitled";

    public SimpleEditorForm(string filename) {
        InitializeComponent();

        if (filename != null) {
            this.filename = filename;
            OpenFile();
        }
    }

    protected void OpenFile() {
        try {
            textBoxEdit.Clear();
            textBoxEdit.Text = File.ReadAllText(filename);
        } catch (IOException ex) {
            MessageBox.Show(ex.Message, "Simple Editor",
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
    }

    private void OnFileNew(object sender, EventArgs e) {
        filename = "Untitled";
        textBoxEdit.Clear();
    }

    private void OnFileOpen(object sender, EventArgs e) {
        if (dlgOpenFile.ShowDialog() == DialogResult.OK) {
            filename = dlgOpenFile.FileName;
            OpenFile();
        }
    }

    private void OnFileSave(object sender, EventArgs e) {

    }

    private void OnFileSaveAs(object sender, EventArgs e) {

    }
    private void InitializeComponent() {
        this.textBoxEdit = new System.Windows.Forms.TextBox();
        this.mainMenu = new System.Windows.Forms.MenuStrip();
        this.miFile = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileNew = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileOpen = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileSave = new System.Windows.Forms.ToolStripMenuItem();
        this.miFileSaveAs = new System.Windows.Forms.ToolStripMenuItem();
        this.dlgOpenFile = new System.Windows.Forms.OpenFileDialog();
        this.mainMenu.SuspendLayout();
        this.SuspendLayout();
        // 
        // textBoxEdit
        // 
        this.textBoxEdit.AcceptsReturn = true;
        this.textBoxEdit.AcceptsTab = true;
        this.textBoxEdit.Dock = System.Windows.Forms.DockStyle.Fill;
        this.textBoxEdit.Location = new System.Drawing.Point(0, 24);
        this.textBoxEdit.Multiline = true;
        this.textBoxEdit.Name = "textBoxEdit";
        this.textBoxEdit.ScrollBars = System.Windows.Forms.ScrollBars.Both;
        this.textBoxEdit.Size = new System.Drawing.Size(562, 219);
        this.textBoxEdit.TabIndex = 0;
        // 
        // mainMenu
        // 
        this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.miFile});
        this.mainMenu.Location = new System.Drawing.Point(0, 0);
        this.mainMenu.Name = "mainMenu";
        this.mainMenu.Size = new System.Drawing.Size(562, 24);
        this.mainMenu.TabIndex = 1;
        this.mainMenu.Text = "menuStrip1";
        // 
        // miFile
        // 
        this.miFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.miFileNew,
            this.miFileOpen,
            this.miFileSave,
            this.miFileSaveAs});
        this.miFile.Name = "miFile";
        this.miFile.Text = "&amp;File";
        // 
        // miFileNew
        // 
        this.miFileNew.Name = "miFileNew";
        this.miFileNew.Text = "&amp;New";
        this.miFileNew.Click += new System.EventHandler(this.OnFileNew);
        // 
        // miFileOpen
        // 
        this.miFileOpen.Name = "miFileOpen";
        this.miFileOpen.Text = "&amp;Open";
        this.miFileOpen.Click += new System.EventHandler(this.OnFileOpen);
        // 
        // miFileSave
        // 
        this.miFileSave.Name = "miFileSave";
        this.miFileSave.Text = "&amp;Save";
        this.miFileSave.Click += new System.EventHandler(this.OnFileSave);
        // 
        // miFileSaveAs
        // 
        this.miFileSaveAs.Name = "miFileSaveAs";
        this.miFileSaveAs.Text = "Save &amp;As";
        this.miFileSaveAs.Click += new System.EventHandler(this.OnFileSaveAs);
        // 
        // dlgOpenFile
        // 
        this.dlgOpenFile.Filter = "Text Documents (*.txt)|*.txt|Wrox Documents (*.wroxtext)|*.wroxtext|All Files|*.*" +
            "";
        this.dlgOpenFile.FilterIndex = 2;
        // 
        // SimpleEditorForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(562, 243);
        this.Controls.Add(this.textBoxEdit);
        this.Controls.Add(this.mainMenu);
        this.MainMenuStrip = this.mainMenu;
        this.Name = "SimpleEditorForm";
        this.Text = "Simple Editor";
        this.mainMenu.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();

    }



    private System.Windows.Forms.TextBox textBoxEdit;
    private System.Windows.Forms.MenuStrip mainMenu;
    private System.Windows.Forms.ToolStripMenuItem miFile;
    private System.Windows.Forms.ToolStripMenuItem miFileNew;
    private System.Windows.Forms.ToolStripMenuItem miFileOpen;
    private System.Windows.Forms.ToolStripMenuItem miFileSave;
    private System.Windows.Forms.ToolStripMenuItem miFileSaveAs;
    private System.Windows.Forms.OpenFileDialog dlgOpenFile;

    [STAThread]
    static void Main(string[] args) {
        string filename = null;
        if (args.Length != 0)
            filename = args[0];

        Application.EnableVisualStyles();
        Application.Run(new SimpleEditorForm(filename));
    }

}