Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Events
Message
 
À
14/11/2004 12:42:20
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Re: Events
Divers
Thread ID:
00961252
Message ID:
00961278
Vues:
6
I think i got it all right now. Thanks for the help.

Here's what i came up with:
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;

namespace Tests
{
	public class _EditBox : System.Windows.Forms.TextBox, IDataAwareControl
	{
		public _EditBox()
		{
			this.Multiline = true;
			this.TextChanged += new System.EventHandler(this._TextChanged);

		}

		public event System.EventHandler DataChange;

		public void OnDataChange(object sender, EventArgs e)
		{
			this.RefreshContent();
		}

		public void RefreshContent()
		{
			this.Width += 1;
		}

		internal void _TextChanged(object sender, System.EventArgs e)
		{
			if (this.DataChange !=null)
				this.DataChange(this, new EventArgs());
		}

	}

	public interface IDataAwareControl
	{
		event EventHandler DataChange;
		void OnDataChange(object sender, EventArgs e);
		void RefreshContent();
	}

	public class Form4 : System.Windows.Forms.Form, IDataAwareControl
	{
		private _EditBox _EditBox1;
		private _EditBox _EditBox2;
		private Label _Label1;

		private System.ComponentModel.Container components = null;

		public Form4()
		{
			InitializeComponent();
		}

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

		private void InitializeComponent()
		{
			this._EditBox1 = new _EditBox();
			this._EditBox2 = new _EditBox();
			this._Label1 = new Label();
			this.SuspendLayout();
			this._EditBox1.Location = new System.Drawing.Point(88, 40);
			this._EditBox1.Multiline = true;
			this._EditBox1.Name = "_EditBox1";
			this._EditBox1.TabIndex = 0;
			this._EditBox1.Text = "_EditBox1";
			this._EditBox2.Location = new System.Drawing.Point(88, 72);
			this._EditBox2.Multiline = true;
			this._EditBox2.Name = "_EditBox2";
			this._EditBox2.TabIndex = 1;
			this._EditBox2.Text = "_EditBox2";
			this._Label1.Location = new System.Drawing.Point(32, 120);
			this._Label1.Name = "_Label1";
			this._Label1.Size = new System.Drawing.Size(200, 96);
			this._Label1.TabIndex = 2;
			this._Label1.Text = "_Label1";
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this._Label1);
			this.Controls.Add(this._EditBox2);
			this.Controls.Add(this._EditBox1);
			this.Name = "Form4";
			this.Text = "Form4";
			this.Load += new System.EventHandler(this.Form4_Load);
			this.ResumeLayout(false);

		}

		private void Form4_Load(object sender, System.EventArgs e)
		{
			foreach( Control c in this.Controls )
			{
				IDataAwareControl d =  c as IDataAwareControl;
				if (d!=null)
				{
					d.DataChange += new EventHandler(this.OnDataChange);
					this.DataChange += new EventHandler(d.OnDataChange);
				}
			}
		}
		public event System.EventHandler DataChange;

		public void OnDataChange(object sender, EventArgs e)
		{
			this._Label1.Text = sender.ToString();
			if (DataChange !=null)
				this.DataChange(this, new EventArgs());
		}

		public void RefreshContent()
		{
		}

		static void Main() 
		{
			Application.Run(new Tests.Form4());
		}	

	}

}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform