|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ToolStrip with ToolStripDropDownButtonThe ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems My question is how do I catch the click event ot these 3 ToolStripMenuItems? I tried the below but it doesn't catch the events: Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormalPriorityToolStripMenuItem.Click, _ HighPriorityToolStripMenuItem.Click 'Declare an object of type ToolStripMenuItem Dim pMenuStripItem As ToolStripMenuItem 'Now let's find out which menu item was clicked pMenuStripItem = CType(sender, ToolStripMenuItem) etc. etc. Should I first declare it as ToolStripDropDownButton? But then how do I get the event of each ToolStripMenuItem? Thanks, Adam On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
<AdamHo***@Webmaster2001.freeserve.co.uk> wrote: Show quoteHide quote >I have a ToolStrip. If you are wanting to use a single Sub to handle the> >The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems > >My question is how do I catch the click event ot these 3 ToolStripMenuItems? > >I tried the below but it doesn't catch the events: > >Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As >System.Object, ByVal e As System.EventArgs) Handles >NormalPriorityToolStripMenuItem.Click, _ > >HighPriorityToolStripMenuItem.Click > > > >'Declare an object of type ToolStripMenuItem > >Dim pMenuStripItem As ToolStripMenuItem > >'Now let's find out which menu item was clicked > >pMenuStripItem = CType(sender, ToolStripMenuItem) > > > >etc. etc. > > > >Should I first declare it as ToolStripDropDownButton? But then how do I get >the event of each ToolStripMenuItem? > > > >Thanks, > >Adam > DropDownMenuItems, 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(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click, MenuItem3.Click Dim MenuItem As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem) MessageBox.Show(MenuItem.Name) 'or MessageBox.Show(MenuItem.Text) 'Use a Select Case statment on the "Name" or "Text" value End Sub Gene 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 Show quoteHide quote "gene kelley" <o***@by.me> wrote in message news:caht52thlvsrmivmpn96mu77l1bu821tun@4ax.com... > On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek" > <AdamHo***@Webmaster2001.freeserve.co.uk> wrote: > >>I have a ToolStrip. >> >>The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems >> >>My question is how do I catch the click event ot these 3 >>ToolStripMenuItems? >> >>I tried the below but it doesn't catch the events: >> >>Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As >>System.Object, ByVal e As System.EventArgs) Handles >>NormalPriorityToolStripMenuItem.Click, _ >> >>HighPriorityToolStripMenuItem.Click >> >> >> >>'Declare an object of type ToolStripMenuItem >> >>Dim pMenuStripItem As ToolStripMenuItem >> >>'Now let's find out which menu item was clicked >> >>pMenuStripItem = CType(sender, ToolStripMenuItem) >> >> >> >>etc. etc. >> >> >> >>Should I first declare it as ToolStripDropDownButton? But then how do I >>get >>the event of each ToolStripMenuItem? >> >> >> >>Thanks, >> >>Adam >> > > If you are wanting to use a single Sub to handle the > DropDownMenuItems, 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(ByVal sender As Object, ByVal e As > System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click, > MenuItem3.Click > Dim MenuItem As ToolStripMenuItem = DirectCast(sender, > ToolStripMenuItem) > MessageBox.Show(MenuItem.Name) > 'or > MessageBox.Show(MenuItem.Text) > > 'Use a Select Case statment on the "Name" or "Text" value > > End Sub > > Gene On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek"
<AdamHo***@Webmaster2001.freeserve.co.uk> wrote: Show quoteHide quote >Many thanks, In the example I gave:> >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 > > > MenuItem.Checked = 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 ToolStripMenuItem For Each c_MenuItem In Me.ToolStripDropDownButton1.DropDownItems c_MenuItem.Checked = False Next where "ToolStripDropDownButton1" 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 Show quoteHide quote >"gene kelley" <o***@by.me> wrote in message >news:caht52thlvsrmivmpn96mu77l1bu821tun@4ax.com... >> On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek" >> <AdamHo***@Webmaster2001.freeserve.co.uk> wrote: >> >>>I have a ToolStrip. >>> >>>The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems >>> >>>My question is how do I catch the click event ot these 3 >>>ToolStripMenuItems? >>> >>>I tried the below but it doesn't catch the events: >>> >>>Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As >>>System.Object, ByVal e As System.EventArgs) Handles >>>NormalPriorityToolStripMenuItem.Click, _ >>> >>>HighPriorityToolStripMenuItem.Click >>> >>> >>> >>>'Declare an object of type ToolStripMenuItem >>> >>>Dim pMenuStripItem As ToolStripMenuItem >>> >>>'Now let's find out which menu item was clicked >>> >>>pMenuStripItem = CType(sender, ToolStripMenuItem) >>> >>> >>> >>>etc. etc. >>> >>> >>> >>>Should I first declare it as ToolStripDropDownButton? But then how do I >>>get >>>the event of each ToolStripMenuItem? >>> >>> >>> >>>Thanks, >>> >>>Adam >>> >> >> If you are wanting to use a single Sub to handle the >> DropDownMenuItems, 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(ByVal sender As Object, ByVal e As >> System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click, >> MenuItem3.Click >> Dim MenuItem As ToolStripMenuItem = DirectCast(sender, >> ToolStripMenuItem) >> MessageBox.Show(MenuItem.Name) >> 'or >> MessageBox.Show(MenuItem.Text) >> >> 'Use a Select Case statment on the "Name" or "Text" value >> >> End Sub >> >> Gene > OK thanks.
I get graphical corruption if I go for the checked method hence went for the icons instead. Thanks, Adam Show quoteHide quote "gene kelley" <o***@by.me> wrote in message news:vqnt52p5anmjp160hmtr434p5vs8i6jg47@4ax.com... > On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek" > <AdamHo***@Webmaster2001.freeserve.co.uk> wrote: > >>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 >> >> >> > > In the example I gave: > > MenuItem.Checked = 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 ToolStripMenuItem > For Each c_MenuItem In > Me.ToolStripDropDownButton1.DropDownItems > c_MenuItem.Checked = False > Next > > where "ToolStripDropDownButton1" 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 > > > > > > > > >>"gene kelley" <o***@by.me> wrote in message >>news:caht52thlvsrmivmpn96mu77l1bu821tun@4ax.com... >>> On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek" >>> <AdamHo***@Webmaster2001.freeserve.co.uk> wrote: >>> >>>>I have a ToolStrip. >>>> >>>>The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems >>>> >>>>My question is how do I catch the click event ot these 3 >>>>ToolStripMenuItems? >>>> >>>>I tried the below but it doesn't catch the events: >>>> >>>>Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As >>>>System.Object, ByVal e As System.EventArgs) Handles >>>>NormalPriorityToolStripMenuItem.Click, _ >>>> >>>>HighPriorityToolStripMenuItem.Click >>>> >>>> >>>> >>>>'Declare an object of type ToolStripMenuItem >>>> >>>>Dim pMenuStripItem As ToolStripMenuItem >>>> >>>>'Now let's find out which menu item was clicked >>>> >>>>pMenuStripItem = CType(sender, ToolStripMenuItem) >>>> >>>> >>>> >>>>etc. etc. >>>> >>>> >>>> >>>>Should I first declare it as ToolStripDropDownButton? But then how do I >>>>get >>>>the event of each ToolStripMenuItem? >>>> >>>> >>>> >>>>Thanks, >>>> >>>>Adam >>>> >>> >>> If you are wanting to use a single Sub to handle the >>> DropDownMenuItems, 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(ByVal sender As Object, ByVal e As >>> System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click, >>> MenuItem3.Click >>> Dim MenuItem As ToolStripMenuItem = DirectCast(sender, >>> ToolStripMenuItem) >>> MessageBox.Show(MenuItem.Name) >>> 'or >>> MessageBox.Show(MenuItem.Text) >>> >>> 'Use a Select Case statment on the "Name" or "Text" value >>> >>> End Sub >>> >>> Gene >>
Count Instances Of String Within String
Large text file import: MVP question Accessing SQL dataset value from button Removing array entry so cumbersome?? Regex references NULL Value - Specified cast is not valid array operators Beginner- 2 Forms & Events Using Streamreader with files in servers How do I keep shared methods on the same namespace level in different files |
|||||||||||||||||||||||