Here is an example.
I have a XtraUserControl subclass named
ToolPanel. Contained in this ToolPanel is a SimpleButton named
sizingButton. I handle its Click event as follows within the ToolPanel
class to toggle its window state.
___________
private void
sizingButton_Click( object sender, EventArgs e )
{
ToggleWindowState();
}
private static
FormWindowState panelWindowState = FormWindowState.Normal;
public static FormWindowState PanelWindowState
{
get { return panelWindowState;
}
set { panelWindowState = value;
}
}
protected virtual void
ToggleWindowState()
{
if( ToolPanel.PanelWindowState
== FormWindowState.Maximized
)
ToolPanel.PanelWindowState =
FormWindowState.Normal;
else
ToolPanel.PanelWindowState = FormWindowState.Maximized;
OnSizingPanel();
Focus();
}
___________
I declared an event within my ToolPanel class named
SizingPanel. The OnSizingPanel method invoked by the ToggleWindowState
method shown above raises my event. It looks like
this.
___________
public static event
EventHandler SizingPanel;
protected void OnSizingPanel()
{
EventHandler handler =
SizingPanel;
if( handler != null
)
handler(
this, EventArgs.Empty );
}
___________
In my main form (which might contain several
instances of a ToolPanel), I bind a handler method to the SizingPanel event
within the form's constructor as follows.
___________
ToolPanel.SizingPanel += new EventHandler( ToolPanel_SizingPanel
);
___________
Within the form's ToolPanel_SizingPanel method, I
hide or show DockPanel objects so that the ToolPanel objects will appear
maximized or restored, depending on the ToolPanel.PanelWindowState value that
was toggled before the event was raised.
The SimpleButton.Click event handler could just as
easily been a BarItem.ItemClick event handler. Instead of an empty
EventArgs object being passed to the custom event, the ItemClickEventArgs
parameter of the ItemClick event could be passed along to the custom
event. The sender parameter of the custom event could still be a reference
to the user control that contains the menu/tool bar.
Let me know if you need additional
information.