Very Interesting Event handling Challenge

ravensnowbird

Newcomer
Joined
Apr 13, 2011
Messages
3
1. Custom Control with 2 Textboxes
Publicly define Int Sum = textbox1 + textbox2 values
2. A new Form and Add the Custrom Control created
A third Textbox which will take value from CustromControl.Sum

The Tricky issue is , Event Should Occur when ever the Textbox1 and Textbox2 values are changed in the Form . and Textbox 3 should get automatically updated.

can anyone who's done this help me with this ?? Its something I've tried using A delegates and events but its never getting invoked in the main form .

Any Help would be appreciated

Thanks
 
The easiest way would be for the custom control to define and raise it's own event when the result of textbox1 + textbox2 changes.

Within the control you would have a single event handler that handles the TextChanged event for both textboxes and would raise the control's custom event if the value changes.

The form would then handle the control's event and would update the content of the third textbox from within this event handler.
 
The easiest way would be for the custom control to define and raise it's own event when the result of textbox1 + textbox2 changes.

Within the control you would have a single event handler that handles the TextChanged event for both textboxes and would raise the control's custom event if the value changes.

The form would then handle the control's event and would update the content of the third textbox from within this event handler.

I've tried Declaring a Delegate and EVENT for the Custom Control , But It throws and error that The Event Declared in the Custom Control is a Method Group

Can you please make an application which does this ? i can understand it easily by tracing . Just Consider this a very small favor.

Thanks for the reply
 
Last edited:
Is there anyone who can help ?? i've Tried using almost all the possible tutorials on the INTERNET . Someone who's experienced can try to help ..
 
C#:
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
	public partial class SampleControl : UserControl
	{
		public EventHandler<SampleChangedEventArgs> SampleEventHandler;
		public event ScrollEventHandler SampleEvent;

		protected void OnSampleEvent(SampleChangedEventArgs e)
		{
			if (SampleEvent != null)
				SampleEventHandler(this, e);
		}

		public SampleControl()
		{
			InitializeComponent();
		}

		private void textBox_TextChanged(object sender, EventArgs e)
		{
			OnSampleEvent(new SampleChangedEventArgs {NewValue = 1});
		}
	}

	public class SampleChangedEventArgs : EventArgs
	{
		public int NewValue { get; set; }
	}
}

That should give you an idea of what the custom control should look like - you just need to make sure the TextChanged even for both textboxes is assigned to the textbox_changed event handler.
 
Back
Top