![]() |
Desktop Development »
Toolbars & Docking windows »
General
Beginner
License: The Code Project Open License (CPOL)
User Customizable ToolStrip with Drag and DropBy pimb2With this .NET library, you can implement a customize toolbar function in your application. |
VB.NET 2.0, .NET 3.0, .NET 3.5VS2008
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
With this library written in VB.NET, you can add a 'Customize Toolbar' function in your application.
I needed a customize toolbar function in my application, but I really couldn't find any library for .NET to implement this. So, I decided to write my own and share it to help others.
In the DLL, there are two functions: ShowCustomizeToolbarWindow and UpdateToolStripWithString. The first function is to load the GUI to customize the window. It returns a string which you can save in your settings. The second function is to reload the ToolStrip if you have saved the result of the first function. The ToolStrip is reloaded with the buttons/separators as the user has chosen.
However, it is quite complicated to use the code. I'm sorry for that. This is what you have to do to get it to work:
Button or some other control on which the user can click to customize the toolbar (you could add it to the ContextMenuStrip of a ToolStrip). 'Set the 3 to the amount of ToolStripButtons
'that can be placed on the ToolStrip
Dim AvailableButtons(3) As ToolStripItem
'Fill the Array with the ToolStripButtons that can be placed on the ToolStrip
AvailableButtons(0) = ToolStripButton1
AvailableButtons(1) = ToolStripButton2
AvailableButtons(2) = ToolStripButton3
AvailableButtons(3) = ToolStripButton4
Dim result = UserCustomizableToolStrip.ShowCustomizeToolbarWindow(ToolStrip1, _
AvailableButtons)
'Optional - to save the current ToolStrip setting (is a String)
My.Settings.ToolStripButtons = result
My.Settings.Save()
If you want to update the ToolStrip while your application is loading, use the following code (in Form1_Load):
'Set the 3 to the amount of ToolStripButtons that can be placed on the ToolStrip
Dim AvailableButtons(3) As ToolStripItem
'Fill the Array with the ToolStripButtons that can be placed on the ToolStrip
AvailableButtons(0) = ToolStripButton1
AvailableButtons(1) = ToolStripButton2
AvailableButtons(2) = ToolStripButton3
AvailableButtons(3) = ToolStripButton4
My.Settings.Reload()
UpdateToolStripWithString(ToolStrip1, AvailableButtons, My.Settings.ToolStripButtons)
Also, you can set the strings used in the form to your own language. You need to create a string array with a length of 10. Here's how to do it:
'Set the 3 to the amount of ToolStripButtons that can be placed on the ToolStrip
Dim AvailableButtons(3) As ToolStripItem
'Fill the Array with the ToolStripButtons that can be placed on the ToolStrip
AvailableButtons(0) = ToolStripButton1
AvailableButtons(1) = ToolStripButton2
AvailableButtons(2) = ToolStripButton3
AvailableButtons(3) = ToolStripButton4
'This is a Dutch example
'Each index of the array has a specific text that is used.
'To see which index is which text, open the demo application,
'they are sorted there (0-9).
Dim langs(100) As String
langs(0) = "Beschikbare knoppen"
langs(1) = "Huidige knoppen"
langs(2) = "OK"
langs(3) = "Annuleren"
langs(4) = "Reset - not used yet"
langs(5) = "Omhoog"
langs(6) = "Omlaag"
langs(7) = "Toevoegen ->"
langs(8) = "<- Verwijderen"
langs(9) = "Werkbalk aanpassen"
langs(10) = "Scheidingsteken"
Dim result = UserCustomizableToolStrip.ShowCustomizeToolbarWindow(ToolStrip1, _
AvailableButtons, langs)
To use the Reset button, you have to supply a default value that is used if the Reset button is clicked. That string is a normal result of the main function, i.e. |ToolStripButton1|Separator|ToolStripButton2.
'Set the 3 to the amount of ToolStripButtons that can be placed on the ToolStrip
Dim AvailableButtons(3) As ToolStripItem
'Fill the Array with the ToolStripButtons that can be placed on the ToolStrip
AvailableButtons(0) = ToolStripButton1
AvailableButtons(1) = ToolStripButton2
AvailableButtons(2) = ToolStripButton3
AvailableButtons(3) = ToolStripButton4
Dim result = UserCustomizableToolStrip.ShowCustomizeToolbarWindow(ToolStrip1, _
AvailableButtons, "|ToolStripButton1|Separator|ToolStripButton2")
I'm only 14 years old, and I'm happy I managed to write this code. If you use this component in your application, please let me know about it. I'd love to see my component in action.
ToolStripSeparators on your ToolStrip in the designer, they must have the word Separator somewhere in their name. .Name used instead of .Tag (you don't have to specify the .Tag properties anymore), fixed some issues with the demo
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Feb 2009 Editor: Deeksha Shenoy |
Copyright 2009 by pimb2 Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |