473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ToolStrip DropDown question

Hi all,

I'm using the new ToolStrip control in a project and I'm running into a
problem that I'm hoping someone can help me with. I am building the
toolstrip in code by adding buttons, seperators, and dropdown buttons
(which have MenuItems added to it). The ToolStrip gets built
perfectly, but the problem I am having is accessing the click event of
the dropdown button's menuitems.

I hope someone can help!!! Thank you so much in advance!

Below is the code I am using to create the toolstrip:

Private Sub ToolStrip1_ItemClicked(ByVal sender As Object, ByVal e
As System.Windows.Forms.ToolStripItemClickedEventArgs ) Handles
ToolStrip1.ItemClicked
Select Case e.ClickedItem.Text
Case "Help"
MsgBox("Help was clicked")
Case "Main Menu"
MsgBox("Main Menu was clicked")
Case "Print"
MsgBox("Print was clicked")
End Select
End Sub

Private Sub AddToolStripItem(Optional ByVal sBtnName As String =
"", Optional ByVal sBtnText As String = "", _
Optional ByVal sDropDownName As String
= "", Optional ByVal sDropDownText As String = "", _
Optional ByVal sMenuItemName As String
= "", Optional ByVal sMenuItemText As String = "")
Dim tsBtn As New ToolStripButton
Dim tsSep As New ToolStripSeparator
Dim tsDrop As New ToolStripDropDownButton
Dim tsMenu As New ToolStripMenuItem
Dim sTempName As String
Dim sTempText As String

tsSep.Name = "Seperator"

If sBtnName <> "" Then
tsBtn.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Tex t
tsBtn.Name = sBtnName
tsBtn.Text = sBtnText

ToolStrip1.Items.Add(tsBtn)
ToolStrip1.Items.Add(tsSep)
ElseIf sDropDownName <> "" Then
tsDrop.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Tex t
tsDrop.Name = "New Dropdown"
tsDrop.Text = "New Dropdown"
tsDrop.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft
ToolStrip1.Items.Add(tsDrop)
ToolStrip1.Items.Add(tsSep)

Do While sMenuItemName <> ""
tsMenu = New ToolStripMenuItem

If InStr(1, sMenuItemName, ",") > 0 Then
sTempName = Mid(sMenuItemName, 1, InStr(1,
sMenuItemName, ",") - 1)
sTempText = Mid(sMenuItemText, 1, InStr(1,
sMenuItemText, ",") - 1)
sMenuItemName = Mid(sMenuItemName, InStr(1,
sMenuItemName, ",") + 1)
sMenuItemText = Mid(sMenuItemText, InStr(1,
sMenuItemText, ",") + 1)
Else
sTempName = sMenuItemName
sTempText = sMenuItemText
sMenuItemName = ""
sMenuItemText = ""
End If

tsMenu.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Tex t
tsMenu.Name = sTempName
tsMenu.Text = sTempText
tsMenu.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft
tsDrop.DropDownItems.Add(tsMenu)
Loop
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddToolStripItem("Help", "Help")
AddToolStripItem("MainMenu", "Main Menu")
AddToolStripItem(, , "AddPolicy", "Add A Policy",
"Item1,Item2,Item3", "Option1,Option2,Option3")
AddToolStripItem("Print", "Print")
End Sub

Nov 21 '05 #1
1 3029
Gator,

I have just deinstalleted my VB2005, and I am in doubt if the items from the
toolstrip have not themselves events.

However if not than is probably this solution very nice (you have to change
the menus for the proper controls)

http://groups.google.com/group/micro...7a88deb?hl=en&
Cor
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: VBTricks.de.vu Webmaster | last post by:
Hello, I'm still reimplementing the GUI of my app using the new toolstrips. My current problem is to autosize a combobox to the available with in the parent toolstrip. There are some buttons...
4
by: Adam Honek | last post by:
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...
4
by: gene kelley | last post by:
The default ToolStrip apparently renders an MS Office Style ToolStrip when the RenderMode is other than "System". When using a BackgroundImage in the ToolStrip, this Office Style border has rounded...
4
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi I'm trying to create a composite control to be used on a ToolStrip, consisting of a ToolStripComboBox and a ToolStripButton. It's going to be a control used to search for text in a grid...
0
by: Shashank | last post by:
Hi all, I have made a toolbar in c# using toolstrip control. I am using xml file to generate menu at runtime and then binding it to the dropdown button. My problem is that when I click the...
0
by: Brian Richards | last post by:
I'm trying to use a ToolStrip but I want to use a table layout to do a 2 column strip. The table layout disables the overflow features you get with the other layout engines. I have two problems....
0
by: Brian Richards | last post by:
I'm trying to use a ToolStrip but I want to use a table layout to do a 2 column strip. The table layout disables the overflow features you get with the other layout engines. I have two problems....
0
by: kjartan93a | last post by:
If you host a ComboBox in a ToolStrip, setting DropDownStyle to DropDown or DropDownList displays the dropdown without affecting the height of the toolbar. I want to emulate that behavior for a...
1
by: Tom P. | last post by:
It's kind of hard to explain (so if you need more just ask) and any help would be greatly appreciated. I am writing a side-by-side file manager. On each side I have a DropDownButton that holds...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.