Home All Groups Group Topic Archive Search About

OnRenderMenuItemBackground question

Author
28 Feb 2006 2:10 PM
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)

....

Author
28 Feb 2006 2:22 PM
Larry Lard
academic wrote:
Show quoteHide quote
> 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

--
Larry Lard
Replies to group please
Author
28 Feb 2006 5:04 PM
academic
perfect

Thanks a lot

Show quoteHide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1141136564.160694.171990@i40g2000cwc.googlegroups.com...
>
>  academic wrote:
>> 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
>
> --
> Larry Lard
> Replies to group please
>