using System; using System.Drawing; using System.Windows.Forms; using System.IO; public class UI : Form { private Label inputFileLabel; private Label outputFileLabel; private Label statusLabel; private Button inputFileButton; private Button outputFileButton; private Button convertButton; public FileStream inputFileStream; public FileStream outputFileStream; public UI() { Size = new Size(380,170); Text = "File Converter"; inputFileLabel = new Label(); inputFileLabel.Text = "(none chosen)"; inputFileLabel.Location = new Point(24,16); inputFileLabel.Size = new Size(190,30); outputFileLabel = new Label(); outputFileLabel.Text = "(none chosen)"; outputFileLabel.Location = new Point(24,56); outputFileLabel.Size = new Size(190,30); statusLabel = new Label(); statusLabel.Location = new Point(24,96); statusLabel.Size = new Size(190,60); inputFileButton = new Button(); inputFileButton.Text = "Select input file"; inputFileButton.Location = new Point(230,16); inputFileButton.Size = new Size(130,20); inputFileButton.Click += new EventHandler(inputFileButtonClicked); outputFileButton = new Button(); outputFileButton.Text = "Select ouput file"; outputFileButton.Location = new Point(230,56); outputFileButton.Size = new Size(130,20); outputFileButton.Click += new EventHandler(outputFileButtonClicked); convertButton = new Button(); convertButton.Text = "Convert"; convertButton.Location = new Point(230,96); convertButton.Size = new Size(100,20); convertButton.Click += new EventHandler(convert); convertButton.Hide(); this.Controls.Add(inputFileLabel); this.Controls.Add(inputFileButton); this.Controls.Add(outputFileLabel); this.Controls.Add(outputFileButton); this.Controls.Add(convertButton); this.Controls.Add(statusLabel); validate(); } private void validate() { if (null!=inputFileStream && null!=outputFileStream) { convertButton.Show(); statusLabel.Text = "Ready to convert"; } else { convertButton.Hide(); statusLabel.Text = "Choose files"; } } private void convert(object o, EventArgs e) { statusLabel.Text = "Converting..."; convertButton.Hide(); // call real convert inputFileStream.Close(); outputFileStream.Close(); convertButton.Show(); statusLabel.Text = "Done converting."; } private void inputFileButtonClicked(object o, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); if (fd.ShowDialog() == DialogResult.OK) { if (outputFileLabel.Text == fd.FileName) { statusLabel.Text = "Input file and output file must be different"; } else { inputFileLabel.Text = fd.FileName; inputFileStream = (FileStream)fd.OpenFile(); validate(); } } } private void outputFileButtonClicked(object o, EventArgs e) { SaveFileDialog fd = new SaveFileDialog(); if (fd.ShowDialog() == DialogResult.OK) { if (inputFileLabel.Text == fd.FileName) { statusLabel.Text = "Input file and output file must be different"; } else { outputFileLabel.Text = fd.FileName; outputFileStream = (FileStream)fd.OpenFile(); validate(); } } } public static void Main() { Application.Run(new UI()); } }