Click here to Skip to main content
6,630,289 members and growing! (23,298 online)
Email Password   helpLost your password?
Desktop Development » Toolbars & Docking windows » General     Beginner License: The Code Project Open License (CPOL)

User Customizable ToolStrip with Drag and Drop

By pimb2

With this .NET library, you can implement a customize toolbar function in your application.
VB.NET 2.0, .NET 3.0, .NET 3.5VS2008
Version:4 (See All)
Posted:2 Feb 2009
Updated:6 Feb 2009
Views:15,473
Bookmarked:50 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
15 votes for this article.
Popularity: 5.42 Rating: 4.61 out of 5

1

2
1 vote, 6.7%
3
4 votes, 26.7%
4
10 votes, 66.7%
5
Source

Introduction

With this library written in VB.NET, you can add a 'Customize Toolbar' function in your application.

Background

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.

Using the Code

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:

  1. Add a 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).
  2. Add the following code to the event handler of that control:
'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")

Points of Interest

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.

Bugs/Notes/etc.

  • No bugs known yet.
  • Not implemented - Nothing
  • WARNING: If you have already put ToolStripSeparators on your ToolStrip in the designer, they must have the word Separator somewhere in their name.

References

History

  • 06-02-2009: Reset button, .Name used instead of .Tag (you don't have to specify the .Tag properties anymore), fixed some issues with the demo
  • 02-02-2009: First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

pimb2


Member

Location: Netherlands Netherlands

Other popular Toolbars & Docking windows articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
GeneralNice work - suggestions for improvements PinmemberTobiasP10:27 15 Feb '09  
GeneralRe: Nice work - suggestions for improvements Pinmemberpimb210:37 15 Feb '09  
GeneralRe: Nice work - suggestions for improvements PinmemberTobiasP11:39 15 Feb '09  
GeneralRe: Nice work - suggestions for improvements Pinmemberpimb25:29 16 Feb '09  
GeneralGreat job! PinmemberShane Story5:03 6 Feb '09  
GeneralRe: Great job! Pinmemberpimb21:32 7 Feb '09  
GeneralNew version Pinmemberpimb29:59 5 Feb '09  
GeneralVery good! One issue though. PinmemberAnt21001:49 4 Feb '09  
GeneralRe: Very good! One issue though. Pinmemberpimb25:34 4 Feb '09  
AnswerRe: Very good! One issue though. PinmemberAnt21007:57 4 Feb '09  
GeneralNames PinmemberMember 451398511:04 3 Feb '09  
GeneralRe: Names Pinmemberpimb29:50 4 Feb '09  
GeneralRe: Names PinmemberMember 45139859:53 4 Feb '09  
GeneralRe: Names Pinmemberpimb29:56 4 Feb '09  
GeneralRe: Names PinmemberMember 45139859:57 4 Feb '09  
GeneralBug Pinmemberpimb28:46 3 Feb '09  
GeneralVery Nice Work! Pinmemberrspercy5816:12 2 Feb '09  
GeneralNice work... PinsupporterPaul Selormey9:43 2 Feb '09  
GeneralGood! PinmemberJose M. Menendez Poó9:15 2 Feb '09  
GeneralRe: Good! Pinmemberpimb29:20 2 Feb '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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