Consolidates Focus-related event handlers preventing key events from being inadvertently sent to Max.
To use, aggregate an instance of this class and hook up the event handlers to a text control. It is recommended that each TextFocusHelper instance manage only one control, ie. that a helper instance not be shared between multiple controls.
Public Member Functions |
|
TextFocusHelper () | |
Default constructor: creates an unbound
TextFocusHelper. |
|
TextFocusHelper (Control target) | |
Construct passing in a Control. |
|
TextFocusHelper (ToolStripControlHost target) | |
Construct passing in a ToolStripControlHost,
such as a ToolStripTextBox or a ToolStripComboBox. |
|
void | BindToTarget (Control target) |
Binds HandleGotFocus to the target's
GotFocus event and HandleLostFocus to the target's LostFocus event.
|
|
void | HandleGotFocus (object sender, EventArgs e) |
Handles GotFocus or any other event where
the sender gains the keyboard focus. |
|
void | HandleLostFocus (object sender, EventArgs e) |
Handles LostFocus or any other event where
the sender loses the keyboard focus. |
MaxCustomControls::TextFocusHelper::TextFocusHelper | ( | ) | [inline] |
Default constructor: creates an unbound TextFocusHelper.
The event handlers must be bound manually.
MaxCustomControls::TextFocusHelper::TextFocusHelper | ( | Control | target | ) | [inline] |
Construct passing in a Control.
The event handlers will be automatically bound to the target's GotFocus and LostFocus events.
target | Target control to which to bind this helper's event handlers. |
MaxCustomControls::TextFocusHelper::TextFocusHelper | ( | ToolStripControlHost | target | ) | [inline] |
Construct passing in a ToolStripControlHost, such as a ToolStripTextBox or a ToolStripComboBox.
The event handlers will be automatically bound to the target's GotFocus and LostFocus events.
target | Target control to which to bind this helper's event handlers. |
void MaxCustomControls::TextFocusHelper::BindToTarget | ( | Control | target | ) | [inline] |
Binds HandleGotFocus to the target's GotFocus event and HandleLostFocus to the target's LostFocus event.
This uses GotFocus and LostFocus instead of Enter and Leave because the lower-level GotFocus and LostFocus events are more reliably called. For example, if this object is bound to an item on a ToolStrip and the item is placed on the Overflow drop down menu, Enter and Leave are never called, but GotFocus and LostFocus are reliably called.
target | Target control to which to bind this helper's event handlers. |
void MaxCustomControls::TextFocusHelper::HandleGotFocus | ( | object | sender, |
EventArgs | e | ||
) | [inline] |
Handles GotFocus or any other event where the sender gains the keyboard focus.
sender | source of the event - the bound control |
e | not used |
void MaxCustomControls::TextFocusHelper::HandleLostFocus | ( | object | sender, |
EventArgs | e | ||
) | [inline] |
Handles LostFocus or any other event where the sender loses the keyboard focus.
sender | source of the event - the bound control |
e | not used |