public TextBoxToolbarItem(ITextBoxAction action, IconSize iconSize) { _action = action; _actionEnabledChangedHandler = new EventHandler(OnActionEnabledChanged); _actionVisibleChangedHandler = new EventHandler(OnActionVisibleChanged); _actionAvailableChangedHandler = new EventHandler(OnActionAvailableChanged); _actionLabelChangedHandler = new EventHandler(OnActionLabelChanged); _actionTooltipChangedHandler = new EventHandler(OnActionTooltipChanged); _actionIconSetChangedHandler = new EventHandler(OnActionIconSetChanged); _actionTextBoxValueChangedHandler = new EventHandler(OnActionTextBoxValueChanged); _actionCueTextChangedHandler = new EventHandler(OnActionCueTextChanged); _action.EnabledChanged += _actionEnabledChangedHandler; _action.VisibleChanged += _actionVisibleChangedHandler; _action.AvailableChanged += _actionAvailableChangedHandler; _action.LabelChanged += _actionLabelChangedHandler; _action.TooltipChanged += _actionTooltipChangedHandler; _action.IconSetChanged += _actionIconSetChangedHandler; _action.TextValueChanged += _actionTextBoxValueChangedHandler; _action.CueTextChanged += _actionCueTextChangedHandler; _iconSize = iconSize; this.Text = _action.TextValue; this.Enabled = _action.Enabled; SetTooltipText(); UpdateCueBanner(); UpdateVisibility(); UpdateEnablement(); UpdateIcon(); }
protected override void Dispose(bool disposing) { if (disposing && _action != null) { // VERY IMPORTANT: instances of this class will be created and discarded frequently // throughout the lifetime of the application // therefore is it extremely important that the event handlers are disconnected // from the underlying _action events // otherwise, this object will hang around for the entire lifetime of the _action object, // even though this object is no longer needed _action.EnabledChanged -= _actionEnabledChangedHandler; _action.VisibleChanged -= _actionVisibleChangedHandler; _action.AvailableChanged -= _actionAvailableChangedHandler; _action.LabelChanged -= _actionLabelChangedHandler; _action.TooltipChanged -= _actionTooltipChangedHandler; _action.IconSetChanged -= _actionIconSetChangedHandler; _action.TextValueChanged -= _actionTextBoxValueChangedHandler; _action.CueTextChanged -= _actionCueTextChangedHandler; _action = null; } base.Dispose(disposing); }
public TextBoxToolbarItem(ITextBoxAction action) : this(action, IconSize.Medium) { }