Howdy!
I want to write a Custom Event Handler replicating textBox1_TextCh anged event handler to update textBox2 with textBox1 text as I type. I tried the following in vain. Please help.
The code snippet:
// CustomEventArgs .cs
[code=c#]
using System;
using System.Collecti ons.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApp lication1
{
delegate void CustomEventHand ler(object sender, CustomEventArgs e);
public class CustomEventArgs : EventArgs
{
string TextBoxText;
public CustomEventArgs (string TextBoxText)
{
this.TextBoxTex t = TextBoxText;
}
internal string TextBoxTextChan ged
{
get
{
return TextBoxText;
}
}
}
}
[/code]
// Form1.cs
[code=C#]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
namespace WindowsFormsApp lication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
private event CustomEventHand ler TextBox1Event;
private void TextBox1_Custom TextChanged(obj ect sender, CustomEventArgs e)
{
textBox2.Text = e.TextBoxTextCh anged;
}
private void OnTextBox1Event (CustomEventArg s e)
{
if (TextBox1Event != null)
{
TextBox1Event(t his, e);
}
}
private void Form1_Load(obje ct sender, EventArgs e)
{
TextBox1Event += new CustomEventHand ler(TextBox1_Cu stomTextChanged );
CustomEventArgs TextBox1EventAr gs = new CustomEventArgs (textBox1.Text) ;
OnTextBox1Event (TextBox1EventA rgs);
}
}
}
[/code]
Thanks.
I want to write a Custom Event Handler replicating textBox1_TextCh anged event handler to update textBox2 with textBox1 text as I type. I tried the following in vain. Please help.
The code snippet:
// CustomEventArgs .cs
[code=c#]
using System;
using System.Collecti ons.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApp lication1
{
delegate void CustomEventHand ler(object sender, CustomEventArgs e);
public class CustomEventArgs : EventArgs
{
string TextBoxText;
public CustomEventArgs (string TextBoxText)
{
this.TextBoxTex t = TextBoxText;
}
internal string TextBoxTextChan ged
{
get
{
return TextBoxText;
}
}
}
}
[/code]
// Form1.cs
[code=C#]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
namespace WindowsFormsApp lication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
private event CustomEventHand ler TextBox1Event;
private void TextBox1_Custom TextChanged(obj ect sender, CustomEventArgs e)
{
textBox2.Text = e.TextBoxTextCh anged;
}
private void OnTextBox1Event (CustomEventArg s e)
{
if (TextBox1Event != null)
{
TextBox1Event(t his, e);
}
}
private void Form1_Load(obje ct sender, EventArgs e)
{
TextBox1Event += new CustomEventHand ler(TextBox1_Cu stomTextChanged );
CustomEventArgs TextBox1EventAr gs = new CustomEventArgs (textBox1.Text) ;
OnTextBox1Event (TextBox1EventA rgs);
}
}
}
[/code]
Thanks.
Comment