I am writing a custom ToolStripProfessionalRenderer
Take for example, the following override:
protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
{
if(e.ToolStrip is MenuStrip)
{
// It never is. It's always ToolStripDropDownMenu
}
}
I guess that OnRenderImageMargin
is called by the drop down menu since this is what will be rendered, however I want to get the parent ToolStrip
/MenuStrip
/StatusStrip
that caused the OnRenderImageMargin
call.
Is this possible?
I thought the
e.ToolStrip.Parent
property would be the key, but it's alwaysnull
.One option is to create a constructor in your
ToolStripProfessionalRenderer
, and pass in a reference to the control.Then pass a reference in when you instantiate it:
An alternative option, modified from this answer.
Forget the ctor and test the
Owner
repeatedly until you get the correct parent control: