CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: how to create an event for enum type value changed?

  1. #1
    Join Date
    Jun 2009
    Posts
    16

    Question [resolved]how to create an event for enum type value changed?

    i creating an user control library , vs 2008, .net framework3.5,

    how can i add a event trigger for an enum type?

    Code:
            public enum period_type { Text, TrackBar };
    
            private period_type period_type_selected;
    
            public period_type Period_Type_Select { get { return period_type_selected; } set { period_type_selected = value; } }
    how can i set the event when period_type_selected has changed? is it possible?

    thx
    chan
    Last edited by Chan1314; September 27th, 2009 at 10:25 PM. Reason: resolved

  2. #2
    Join Date
    Jun 2009
    Posts
    16

    Re: how to create an event for enum type value changed?

    problem solved.
    i added code into the function Period_Type_Select.

    chan

  3. #3
    Join Date
    Jul 2006
    Posts
    297

    Re: how to create an event for enum type value changed?

    I assume you could try something like this.

    Code:
    public period_type Period_Type 
    {
        get { ...... }
        set
        {
               if(value != period_type_selected)
                    // Fire Enum Event changed here
    
               period_type_selected = value;
         }
    }

  4. #4
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: how to create an event for enum type value changed?

    You would probably want to change the value first before firing the event just to make sure the value actually gets changed. If you fire the event then your calling code which is essentially unknown to the program until runtime and that code could throw an exception or blow up in some other way and cause the value to not be changed.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  5. #5
    Join Date
    Jul 2006
    Posts
    297

    Re: how to create an event for enum type value changed?

    Quote Originally Posted by RaleTheBlade View Post
    You would probably want to change the value first before firing the event just to make sure the value actually gets changed. If you fire the event then your calling code which is essentially unknown to the program until runtime and that code could throw an exception or blow up in some other way and cause the value to not be changed.
    Yeah you're right

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)