Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSave and restore toolbar configuration when a program starts and stops in VB .NET
DescriptionThis example shows how to save and restore toolbar configuration when a program starts and stops in VB .NET. It uses SaveSetting and GetSetting to save and restore the buttons' Visible properties in the Registry.
KeywordsToolBar, customize, customization, configure, VB.NET
CategoriesVB.NET, Controls, Software Engineering
 
In VB 6, the Toolbar control provides SaveToolbar and RestoreToolbar methods to save and restore a Toobar's configuration in the Registry. This feature is missing in VB .NET.

This program uses the SaveToolbar and RestoreToolbar subroutines shown in the following code to save and restore the ToolBar buttons' Visible property values in the Registry. The main program should call these methods in its Closing and Load event handlers.

The SaveToolbar subroutine loops through the ToolBar's buttons, using SaveSetting to save their Visible values in the Registry.

RestoreToolbar again loops through the ToolBar's buttons, this time using GetSetting to read their Visible values from the Registry.

 
' Save the ToolBar's Button's Visible properties.
Public Sub SaveToolbar(ByVal client_toolbar As ToolBar, _
    ByVal app_name As String)
    ' Save each button's Visible value.
    For i As Integer = 0 To client_toolbar.Buttons.Count - 1
        SaveSetting(app_name, "ToolBarSettings", _
            i.ToString, _
                client_toolbar.Buttons(i).Visible.ToString)
    Next i
End Sub

' Restore the ToolBar's Button's Visible properties.
Public Sub RestoreToolbar(ByVal client_toolbar As ToolBar, _
    ByVal app_name As String)
    ' Restore each button's Visible value.
    For i As Integer = 0 To client_toolbar.Buttons.Count - 1
        ' See if this button's Visible value is true.
        ' Note that we use the current value as 
        ' defined by the program at design time
        ' as the default.
        If CBool(GetSetting(app_name, "ToolBarSettings", _
            i.ToString, _
                client_toolbar.Buttons(i).Visible.ToString)) _
                _
        Then
            client_toolbar.Buttons(i).Visible = True
        Else
            client_toolbar.Buttons(i).Visible = False
        End If
    Next i
End Sub
 
Note that you could add the user's name to the Registry section or key names to let different users save their own customizations.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated