ToolStrip with ToolStripDropDownButton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Honek

    #1

    ToolStrip with ToolStripDropDownButton

    I have a ToolStrip.

    The ToolStrip has a ToolStripDropDo wnButton with 3 ToolStripMenuIt ems

    My question is how do I catch the click event ot these 3 ToolStripMenuIt ems?

    I tried the below but it doesn't catch the events:

    Private Sub LowPriorityTool StripMenuItem_C lick(ByVal sender As
    System.Object, ByVal e As System.EventArg s) Handles
    NormalPriorityT oolStripMenuIte m.Click, _

    HighPriorityToo lStripMenuItem. Click



    'Declare an object of type ToolStripMenuIt em

    Dim pMenuStripItem As ToolStripMenuIt em

    'Now let's find out which menu item was clicked

    pMenuStripItem = CType(sender, ToolStripMenuIt em)



    etc. etc.



    Should I first declare it as ToolStripDropDo wnButton? But then how do I get
    the event of each ToolStripMenuIt em?



    Thanks,

    Adam


  • gene kelley

    #2
    Re: ToolStrip with ToolStripDropDo wnButton

    On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
    <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
    [color=blue]
    >I have a ToolStrip.
    >
    >The ToolStrip has a ToolStripDropDo wnButton with 3 ToolStripMenuIt ems
    >
    >My question is how do I catch the click event ot these 3 ToolStripMenuIt ems?
    >
    >I tried the below but it doesn't catch the events:
    >
    >Private Sub LowPriorityTool StripMenuItem_C lick(ByVal sender As
    >System.Objec t, ByVal e As System.EventArg s) Handles
    >NormalPriority ToolStripMenuIt em.Click, _
    >
    >HighPriorityTo olStripMenuItem .Click
    >
    >
    >
    >'Declare an object of type ToolStripMenuIt em
    >
    >Dim pMenuStripItem As ToolStripMenuIt em
    >
    >'Now let's find out which menu item was clicked
    >
    >pMenuStripIt em = CType(sender, ToolStripMenuIt em)
    >
    >
    >
    >etc. etc.
    >
    >
    >
    >Should I first declare it as ToolStripDropDo wnButton? But then how do I get
    >the event of each ToolStripMenuIt em?
    >
    >
    >
    >Thanks,
    >
    >Adam
    >[/color]

    If you are wanting to use a single Sub to handle the
    DropDownMenuIte ms, then just create a Sub similar to this (the three
    DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
    unique text string ). In this case the DropDownItem click events,
    themselves, are not used:

    Private Sub WhichMenuItem(B yVal sender As Object, ByVal e As
    System.EventArg s) Handles MenuItem1.Click , MenuItem2.Click ,
    MenuItem3.Click
    Dim MenuItem As ToolStripMenuIt em = DirectCast(send er,
    ToolStripMenuIt em)
    MessageBox.Show (MenuItem.Name)
    'or
    MessageBox.Show (MenuItem.Text)

    'Use a Select Case statment on the "Name" or "Text" value

    End Sub

    Gene

    Comment

    • Adam Honek

      #3
      Re: ToolStrip with ToolStripDropDo wnButton

      Many thanks,

      Works a treat.

      Only problem is when I do
      pMenuStripItem. Checked = True



      I get graphical corruption instead of a tick. It's an orange rectangle with
      a very tiny tick in it.

      I tried to make it bold instead so the user knows which is currently active
      however the bold and font properties are read only.

      Anything else I can use to mark the selection?

      Thanks,

      Adam



      "gene kelley" <okay@by.me> wrote in message
      news:caht52thlv srmivmpn96mu77l 1bu821tun@4ax.c om...[color=blue]
      > On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
      > <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
      >[color=green]
      >>I have a ToolStrip.
      >>
      >>The ToolStrip has a ToolStripDropDo wnButton with 3 ToolStripMenuIt ems
      >>
      >>My question is how do I catch the click event ot these 3
      >>ToolStripMenu Items?
      >>
      >>I tried the below but it doesn't catch the events:
      >>
      >>Private Sub LowPriorityTool StripMenuItem_C lick(ByVal sender As
      >>System.Object , ByVal e As System.EventArg s) Handles
      >>NormalPriorit yToolStripMenuI tem.Click, _
      >>
      >>HighPriorityT oolStripMenuIte m.Click
      >>
      >>
      >>
      >>'Declare an object of type ToolStripMenuIt em
      >>
      >>Dim pMenuStripItem As ToolStripMenuIt em
      >>
      >>'Now let's find out which menu item was clicked
      >>
      >>pMenuStripIte m = CType(sender, ToolStripMenuIt em)
      >>
      >>
      >>
      >>etc. etc.
      >>
      >>
      >>
      >>Should I first declare it as ToolStripDropDo wnButton? But then how do I
      >>get
      >>the event of each ToolStripMenuIt em?
      >>
      >>
      >>
      >>Thanks,
      >>
      >>Adam
      >>[/color]
      >
      > If you are wanting to use a single Sub to handle the
      > DropDownMenuIte ms, then just create a Sub similar to this (the three
      > DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
      > unique text string ). In this case the DropDownItem click events,
      > themselves, are not used:
      >
      > Private Sub WhichMenuItem(B yVal sender As Object, ByVal e As
      > System.EventArg s) Handles MenuItem1.Click , MenuItem2.Click ,
      > MenuItem3.Click
      > Dim MenuItem As ToolStripMenuIt em = DirectCast(send er,
      > ToolStripMenuIt em)
      > MessageBox.Show (MenuItem.Name)
      > 'or
      > MessageBox.Show (MenuItem.Text)
      >
      > 'Use a Select Case statment on the "Name" or "Text" value
      >
      > End Sub
      >
      > Gene[/color]


      Comment

      • gene kelley

        #4
        Re: ToolStrip with ToolStripDropDo wnButton

        On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek"
        <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
        [color=blue]
        >Many thanks,
        >
        >Works a treat.
        >
        >Only problem is when I do
        >pMenuStripItem .Checked = True
        >
        >
        >
        >I get graphical corruption instead of a tick. It's an orange rectangle with
        >a very tiny tick in it.
        >
        >I tried to make it bold instead so the user knows which is currently active
        >however the bold and font properties are read only.
        >
        >Anything else I can use to mark the selection?
        >
        >Thanks,
        >
        >Adam
        >
        >
        >[/color]

        In the example I gave:

        MenuItem.Checke d = True

        Renders a checked menu item as expected which is an orange rectangle
        filled with a check mark character - the normal XP style. AFAIK, the
        check box graphic has no relation to fonts.

        Of course, if using checked items and you only want one item checked,
        you will have to clear all the checked items before the Select Case
        statement. In the previous example, you could add something like:

        Dim c_MenuItem As ToolStripMenuIt em
        For Each c_MenuItem In
        Me.ToolStripDro pDownButton1.Dr opDownItems
        c_MenuItem.Chec ked = False
        Next

        where "ToolStripDropD ownButton1" was the name of the DropDown.


        In this type of situation, rather than a checked item, I have a
        particular, same icon on each of the menu items and simply toggle the
        icon to it's "selected" version to indicate which item is in use.


        Gene







        [color=blue]
        >"gene kelley" <okay@by.me> wrote in message
        >news:caht52thl vsrmivmpn96mu77 l1bu821tun@4ax. com...[color=green]
        >> On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
        >> <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
        >>[color=darkred]
        >>>I have a ToolStrip.
        >>>
        >>>The ToolStrip has a ToolStripDropDo wnButton with 3 ToolStripMenuIt ems
        >>>
        >>>My question is how do I catch the click event ot these 3
        >>>ToolStripMen uItems?
        >>>
        >>>I tried the below but it doesn't catch the events:
        >>>
        >>>Private Sub LowPriorityTool StripMenuItem_C lick(ByVal sender As
        >>>System.Objec t, ByVal e As System.EventArg s) Handles
        >>>NormalPriori tyToolStripMenu Item.Click, _
        >>>
        >>>HighPriority ToolStripMenuIt em.Click
        >>>
        >>>
        >>>
        >>>'Declare an object of type ToolStripMenuIt em
        >>>
        >>>Dim pMenuStripItem As ToolStripMenuIt em
        >>>
        >>>'Now let's find out which menu item was clicked
        >>>
        >>>pMenuStripIt em = CType(sender, ToolStripMenuIt em)
        >>>
        >>>
        >>>
        >>>etc. etc.
        >>>
        >>>
        >>>
        >>>Should I first declare it as ToolStripDropDo wnButton? But then how do I
        >>>get
        >>>the event of each ToolStripMenuIt em?
        >>>
        >>>
        >>>
        >>>Thanks,
        >>>
        >>>Adam
        >>>[/color]
        >>
        >> If you are wanting to use a single Sub to handle the
        >> DropDownMenuIte ms, then just create a Sub similar to this (the three
        >> DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
        >> unique text string ). In this case the DropDownItem click events,
        >> themselves, are not used:
        >>
        >> Private Sub WhichMenuItem(B yVal sender As Object, ByVal e As
        >> System.EventArg s) Handles MenuItem1.Click , MenuItem2.Click ,
        >> MenuItem3.Click
        >> Dim MenuItem As ToolStripMenuIt em = DirectCast(send er,
        >> ToolStripMenuIt em)
        >> MessageBox.Show (MenuItem.Name)
        >> 'or
        >> MessageBox.Show (MenuItem.Text)
        >>
        >> 'Use a Select Case statment on the "Name" or "Text" value
        >>
        >> End Sub
        >>
        >> Gene[/color]
        >[/color]

        Comment

        • Adam Honek

          #5
          Re: ToolStrip with ToolStripDropDo wnButton

          OK thanks.

          I get graphical corruption if I go for the checked method hence went for the
          icons instead.

          Thanks,
          Adam

          "gene kelley" <okay@by.me> wrote in message
          news:vqnt52p5an mjp160hmtr434p5 vs8i6jg47@4ax.c om...[color=blue]
          > On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek"
          > <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
          >[color=green]
          >>Many thanks,
          >>
          >>Works a treat.
          >>
          >>Only problem is when I do
          >>pMenuStripIte m.Checked = True
          >>
          >>
          >>
          >>I get graphical corruption instead of a tick. It's an orange rectangle
          >>with
          >>a very tiny tick in it.
          >>
          >>I tried to make it bold instead so the user knows which is currently
          >>active
          >>however the bold and font properties are read only.
          >>
          >>Anything else I can use to mark the selection?
          >>
          >>Thanks,
          >>
          >>Adam
          >>
          >>
          >>[/color]
          >
          > In the example I gave:
          >
          > MenuItem.Checke d = True
          >
          > Renders a checked menu item as expected which is an orange rectangle
          > filled with a check mark character - the normal XP style. AFAIK, the
          > check box graphic has no relation to fonts.
          >
          > Of course, if using checked items and you only want one item checked,
          > you will have to clear all the checked items before the Select Case
          > statement. In the previous example, you could add something like:
          >
          > Dim c_MenuItem As ToolStripMenuIt em
          > For Each c_MenuItem In
          > Me.ToolStripDro pDownButton1.Dr opDownItems
          > c_MenuItem.Chec ked = False
          > Next
          >
          > where "ToolStripDropD ownButton1" was the name of the DropDown.
          >
          >
          > In this type of situation, rather than a checked item, I have a
          > particular, same icon on each of the menu items and simply toggle the
          > icon to it's "selected" version to indicate which item is in use.
          >
          >
          > Gene
          >
          >
          >
          >
          >
          >
          >
          >[color=green]
          >>"gene kelley" <okay@by.me> wrote in message
          >>news:caht52th lvsrmivmpn96mu7 7l1bu821tun@4ax .com...[color=darkred]
          >>> On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
          >>> <AdamHonek@Webm aster2001.frees erve.co.uk> wrote:
          >>>
          >>>>I have a ToolStrip.
          >>>>
          >>>>The ToolStrip has a ToolStripDropDo wnButton with 3 ToolStripMenuIt ems
          >>>>
          >>>>My question is how do I catch the click event ot these 3
          >>>>ToolStripMe nuItems?
          >>>>
          >>>>I tried the below but it doesn't catch the events:
          >>>>
          >>>>Private Sub LowPriorityTool StripMenuItem_C lick(ByVal sender As
          >>>>System.Obje ct, ByVal e As System.EventArg s) Handles
          >>>>NormalPrior ityToolStripMen uItem.Click, _
          >>>>
          >>>>HighPriorit yToolStripMenuI tem.Click
          >>>>
          >>>>
          >>>>
          >>>>'Declare an object of type ToolStripMenuIt em
          >>>>
          >>>>Dim pMenuStripItem As ToolStripMenuIt em
          >>>>
          >>>>'Now let's find out which menu item was clicked
          >>>>
          >>>>pMenuStripI tem = CType(sender, ToolStripMenuIt em)
          >>>>
          >>>>
          >>>>
          >>>>etc. etc.
          >>>>
          >>>>
          >>>>
          >>>>Should I first declare it as ToolStripDropDo wnButton? But then how do I
          >>>>get
          >>>>the event of each ToolStripMenuIt em?
          >>>>
          >>>>
          >>>>
          >>>>Thanks,
          >>>>
          >>>>Adam
          >>>>
          >>>
          >>> If you are wanting to use a single Sub to handle the
          >>> DropDownMenuIte ms, then just create a Sub similar to this (the three
          >>> DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
          >>> unique text string ). In this case the DropDownItem click events,
          >>> themselves, are not used:
          >>>
          >>> Private Sub WhichMenuItem(B yVal sender As Object, ByVal e As
          >>> System.EventArg s) Handles MenuItem1.Click , MenuItem2.Click ,
          >>> MenuItem3.Click
          >>> Dim MenuItem As ToolStripMenuIt em = DirectCast(send er,
          >>> ToolStripMenuIt em)
          >>> MessageBox.Show (MenuItem.Name)
          >>> 'or
          >>> MessageBox.Show (MenuItem.Text)
          >>>
          >>> 'Use a Select Case statment on the "Name" or "Text" value
          >>>
          >>> End Sub
          >>>
          >>> Gene[/color]
          >>[/color][/color]


          Comment

          Working...