CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2007
    Posts
    43

    object event help!

    hello guru

    how to dynamically know that an specific object event occurred during runtime?


    thanks!

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: object event help!

    As far as I know you will have to handle the event.

  3. #3
    Join Date
    Feb 2007
    Posts
    43

    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!

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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?

  5. #5
    Join Date
    Feb 2007
    Posts
    43

    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).

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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.

  7. #7
    Join Date
    Feb 2007
    Posts
    43

    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

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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);

  9. #9
    Join Date
    Feb 2007
    Posts
    43

    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

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: object event help!

    I wouldn't know how to do that. Maybe someone else will suggest something.

  11. #11
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: object event help!

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured