Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)
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

Edited by ravensnowbird
  • Administrators
Posted

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class SampleControl : UserControl
{
	public EventHandler 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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...