ravensnowbird Posted April 13, 2011 Posted April 13, 2011 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 Quote
Administrators PlausiblyDamp Posted April 13, 2011 Administrators Posted April 13, 2011 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ravensnowbird Posted April 13, 2011 Author Posted April 13, 2011 (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 April 13, 2011 by ravensnowbird Quote
ravensnowbird Posted April 14, 2011 Author Posted April 14, 2011 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 .. Quote
Administrators PlausiblyDamp Posted April 14, 2011 Administrators Posted April 14, 2011 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.