-
March 11th, 2008, 07:06 PM
#1
object event help!
hello guru
how to dynamically know that an specific object event occurred during runtime?
thanks!
-
March 11th, 2008, 07:10 PM
#2
Re: object event help!
As far as I know you will have to handle the event.
-
March 11th, 2008, 07:15 PM
#3
Re: object event help!
hello Shuja Ali,
added to what i posted, i want to know or get the object from a control where the specific event occured during runtime.
i hope you guyz can help me here.
big thanks!
-
March 11th, 2008, 07:21 PM
#4
Re: object event help!
I am unable to understand your question. Can you explain it with an example as to what exactly you are trying to do?
-
March 11th, 2008, 07:42 PM
#5
Re: object event help!
hello there Shuja Ali,
here's a clearer picture (i hope)
i have a control(form/usercontrol, etc) which has lots of object (textbox,combobox, radiobutton, etc)...
now my problem is, how will i get programmatically or during runtime that an specific event occur to each object (textbox,combobox, radiobutton, etc) in that control (form/usercontrol, etc).
-
March 11th, 2008, 07:56 PM
#6
Re: object event help!
Each of these controls has an Event which can be handled. If you select the control in the design view and open properties windows(by pressing F4), you will see a lightning flash icon in the properties window. Click on this icon and you will get a list of all the Events that this control exposes. You will need to handle these events and write code for the ones that you are interested in. For example a Button will have a Click event and you will write a Click Event handler to handle its Click event.
Do you have MSDN documentation? You should go through the documentation too to understand the events.
-
March 11th, 2008, 08:20 PM
#7
Re: object event help!
hello Shuja Ali
i know that. but that is not my target.
my target is to get obtain those event during runtime. without of course
doing it in design time
-
March 11th, 2008, 08:31 PM
#8
Re: object event help!
Well you will have to add handler to the event from within your code.
Something like this would work
Code:
textBox1.TextChanged += new TextChangedEventHandler(SomeMethod);
-
March 11th, 2008, 08:39 PM
#9
Re: object event help!
hello again.
here's a clearer example:
i have a form1 and with two object, text1 and text2
how will i know from form1 that text1 raises an event without assigning any predefined handlers for such event
thanks again
-
March 12th, 2008, 04:25 AM
#10
Re: object event help!
I wouldn't know how to do that. Maybe someone else will suggest something.
-
March 12th, 2008, 06:03 AM
#11
Re: object event help!
Originally Posted by radicallycritic
hello again.
here's a clearer example:
i have a form1 and with two object, text1 and text2
how will i know from form1 that text1 raises an event without assigning any predefined handlers for such event
thanks again
If I understand your requirement correctly you want something like this..
Code:
public class View
{
private TextObject textObject = new TextObject();
public View()
{
// subscribe to the event the object can raise
textObject.TextChanged += new EventHandler(OnTextObjectChanged);
}
private void OnTextObjectChanged(object sender, EventArgs e)
{
// handle the event here
}
}
public class TextObject
{
public EventHandler TextChanged;
// Use this method internally to raise the event
private void OnTextChanged()
{
if (TextChanged != null)
{
TextChanged(this, new EventArgs());
}
}
}
So you TextObject and you have a View where you use the text object. The text object can notify when its text has changed. The view can subscribe to that event so that it can handle it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|