OnRenderMenuItemBackground question

  • Thread starter Thread starter academic
  • Start date Start date
A

academic

I'm trying the following but can't determine in the sub if e points to a
item that is checked. I did a quick watch and looked and looked but can not
find anything that I can use to determine if it is checked.



Am I missing something? Is it there?



Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As
ToolStripItemRenderEventArgs)

If e.Item.Tag Is Nothing Then Exit Sub

MyBase.OnRenderMenuItemBackground(e)

....
 
academic said:
I'm trying the following but can't determine in the sub if e points to a
item that is checked. I did a quick watch and looked and looked but can not
find anything that I can use to determine if it is checked.

Am I missing something? Is it there?

Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As
ToolStripItemRenderEventArgs)

If e.Item.Tag Is Nothing Then Exit Sub

MyBase.OnRenderMenuItemBackground(e)

...

e.Item is declared as a ToolStripItem, which is a base class for *all*
the various bits and pieces that can appear on a ToolStrip. Not all of
these can be 'checked', so ToolStripItem doesn't have such a property.
BUT ToolStripMenuItem (which I suspect is what you are interested in)
can be 'checked' and does have a Checked property. And
ToolStripMenuItem *derives* from ToolStripItem, so the e.Item we are
passed might actually *be* a ToolStripMenuItem. So we check (hoho):

Protected Overrides Sub OnRenderMenuItemBackground(_
ByVal e As ToolStripItemRenderEventArgs)

If e.Item.Tag Is Nothing Then Exit Sub

MyBase.OnRenderMenuItemBackground(e)

' new stuff
If TypeOf e.Item Is ToolStripMenuItem Then
Dim menuitem As ToolStripMenuItem = DirectCast(e.Item,
ToolStripMenuItem)

' now do stuff that depends on menuitem.Checked
End If
 
perfect

Thanks a lot

Larry Lard said:
e.Item is declared as a ToolStripItem, which is a base class for *all*
the various bits and pieces that can appear on a ToolStrip. Not all of
these can be 'checked', so ToolStripItem doesn't have such a property.
BUT ToolStripMenuItem (which I suspect is what you are interested in)
can be 'checked' and does have a Checked property. And
ToolStripMenuItem *derives* from ToolStripItem, so the e.Item we are
passed might actually *be* a ToolStripMenuItem. So we check (hoho):

Protected Overrides Sub OnRenderMenuItemBackground(_
ByVal e As ToolStripItemRenderEventArgs)

If e.Item.Tag Is Nothing Then Exit Sub

MyBase.OnRenderMenuItemBackground(e)

' new stuff
If TypeOf e.Item Is ToolStripMenuItem Then
Dim menuitem As ToolStripMenuItem = DirectCast(e.Item,
ToolStripMenuItem)

' now do stuff that depends on menuitem.Checked
End If
 
Back
Top