J
Juan C. Olivares
Hi:
This is a little program. It has a thread that calls trough Invoke to a
method called Draw. The Draw method draw elements within the Panel control.
For some reason, the program does not close sometimes. Please semd me
comments about this.
Thanks!
Juan C. Olivares
// project created on 11-07-2003 at 0:31
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace MyFormProject
{
delegate void DelegateCallDraw ();
class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel;
private DelegateCallDraw CallDraw;
public MainForm()
{
InitializeComponent();
panel.AutoScroll = true;
// Add controls
this.Draw ();
// Create delegate
CallDraw = new DelegateCallDraw (Draw);
// StartThread
Thread thread = new Thread (new ThreadStart (StartTimer));
thread.Start ();
}
// This method is used in the forms designer.
// Change this method on you own risk
void InitializeComponent() {
this.panel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel
//
this.panel.Location = new System.Drawing.Point(16, 16);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(264, 128);
this.panel.TabIndex = 0;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 161);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel});
this.Name = "MainForm";
this.Text = "This is my form";
this.ResumeLayout(false);
}
private void Draw ()
{
panel.Controls.Clear ();
panel.SuspendLayout ();
for (int i = 1; i <= 20; i++) {
TextBox tb = new TextBox ();
tb.Text = i.ToString ();
tb.Location = new Point (0, (i - 1) * tb.Height);
panel.Controls.Add (tb);
}
panel.ResumeLayout ();
}
private void StartTimer ()
{
while (true) {
// Sleep 10 secs
Thread.Sleep (1000 * 10);
// Call draw
this.Invoke (this.CallDraw);
}
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
}
}
This is a little program. It has a thread that calls trough Invoke to a
method called Draw. The Draw method draw elements within the Panel control.
For some reason, the program does not close sometimes. Please semd me
comments about this.
Thanks!
Juan C. Olivares
// project created on 11-07-2003 at 0:31
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace MyFormProject
{
delegate void DelegateCallDraw ();
class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel;
private DelegateCallDraw CallDraw;
public MainForm()
{
InitializeComponent();
panel.AutoScroll = true;
// Add controls
this.Draw ();
// Create delegate
CallDraw = new DelegateCallDraw (Draw);
// StartThread
Thread thread = new Thread (new ThreadStart (StartTimer));
thread.Start ();
}
// This method is used in the forms designer.
// Change this method on you own risk
void InitializeComponent() {
this.panel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel
//
this.panel.Location = new System.Drawing.Point(16, 16);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(264, 128);
this.panel.TabIndex = 0;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 161);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel});
this.Name = "MainForm";
this.Text = "This is my form";
this.ResumeLayout(false);
}
private void Draw ()
{
panel.Controls.Clear ();
panel.SuspendLayout ();
for (int i = 1; i <= 20; i++) {
TextBox tb = new TextBox ();
tb.Text = i.ToString ();
tb.Location = new Point (0, (i - 1) * tb.Height);
panel.Controls.Add (tb);
}
panel.ResumeLayout ();
}
private void StartTimer ()
{
while (true) {
// Sleep 10 secs
Thread.Sleep (1000 * 10);
// Call draw
this.Invoke (this.CallDraw);
}
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
}
}