using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication9
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.statusBar1);
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(192, 168);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(8, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(176, 121);
this.listBox1.TabIndex = 0;
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(3, 143);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(186, 22);
this.statusBar1.TabIndex = 1;
this.statusBar1.Text = "statusBar1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(208, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 24);
this.label1.TabIndex = 1;
this.label1.Text = "Show counter running while the listbox loads:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "0";
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// button1
//
this.button1.Location = new System.Drawing.Point(208, 152);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 23);
this.button1.TabIndex = 3;
this.button1.Text = "Do it";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(344, 182);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private System.Timers.Timer Tmr = new System.Timers.Timer(1000);
private int secondslapsed = 0;
private System.Threading.Thread loadThread;
private void Form1_Load(object sender, System.EventArgs e)
{
System.Threading.ThreadStart ThrdStart = new System.Threading.ThreadStart(LoadListbox1);
loadThread = new System.Threading.Thread(ThrdStart);
Tmr.Elapsed += new System.Timers.ElapsedEventHandler(TmrElapse);
button1.Click += new System.EventHandler(ClickMe);
Tmr.Start();
}
public void TmrElapse(object source, System.Timers.ElapsedEventArgs e)
{
secondslapsed++;
this.textBox1.Text = Convert.ToString(secondslapsed);
}
public void ClickMe(object source, System.EventArgs e)
{
if (loadThread.ThreadState != System.Threading.ThreadState.Running)
loadThread.Start();
}
public void LoadListbox1()
{
String input;
System.IO.TextReader txtReader = System.IO.File.OpenText("C:\\SuperCargantuousFile.txt");
while((input = txtReader.ReadLine())!= null)
{
listBox1.Items.Add(input);
}
txtReader.Close();
}
}
}