Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Define Event
Message
De
02/04/2009 17:52:42
John Baird
Coatesville, Pennsylvanie, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01392879
Message ID:
01392883
Vues:
51
>I don't know why but Delegate and Events have always been difficult for me to grasp. Now I have the need to define a ButtonClicked event for a custom control I wrote. I can't seem to get it right. Can someone help?


This shows you an event from my stuff, just change it to ButtonClick or whatever. Hope this helps...
        public event EventHandler<NavBarGroupChangedEventArgs> NavBarGroupChanged;

        /// <summary>
        /// Triggers the NavBarGroupChanged event.
        /// </summary>
        public void RaiseNavBarGroupChanged(string group, string lastGroup, NavBarControl control, SplitContainerControl containerControl)
        {
            var handler = this.NavBarGroupChanged;
            if (handler != null)
            {
                handler(this, new NavBarGroupChangedEventArgs(group, lastGroup, control, containerControl));
            }
        }

    /// <summary>
    /// Provide args for the event
    /// </summary>
    public class NavBarGroupChangedEventArgs : EventArgs
    {

        private readonly string _activeGroup;
        private readonly string _lastGroup;
        private readonly NavBarControl _navControl;
        private readonly SplitContainerControl _containerControl;

        public NavBarGroupChangedEventArgs(string activeGroup, string lastGroup, NavBarControl control, SplitContainerControl containerControl)
        {
            _activeGroup = activeGroup;
            _lastGroup = lastGroup;
            _navControl = control;
            _containerControl = containerControl;
        }

        public string ActiveGroup
        {
            get
            {
                return _activeGroup;
            }
        }

        public string LastGroup
        {
            get
            {
                return _lastGroup;
            }
        }

        public NavBarControl navControl
        {
            get
            {
                return _navControl;
            }
        }
    
        public SplitContainerControl ContainerControl
        {
            get
            {
                return _containerControl;
            }
        }
    }
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform