Newsgroup: it.comp.lang.visual-basic
Titolo: Gestione Toolbar vb5

 
Questo è il form che io uso per le mie toolbar. Nella toolbar del form
principale inserisco solo i pulsanti per aprire e salvare i file e quelli
per visualizzare/nascondere le toolbar create con form simili a questo.
Non fa tutto quello che fanno le toolbar create automaticamente con
VC++, ma il programma che le usa è "bellino".
ilsPulsanti è l'image list con le immagini dei pulsanti
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
Begin VB.Form frmToolbar 
   BorderStyle     =   5  'Sizable ToolWindow
   Caption         =   "Pippo"
   ClientHeight    =   1560
   ClientLeft      =   60
   ClientTop       =   330
   ClientWidth     =   1395
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1560
   ScaleWidth      =   1395
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin ComctlLib.Toolbar Toolbar1 
      Align           =   1  'Align Top
      Height          =   420
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   741
      Appearance      =   1
      _Version        =   327682
   End
   Begin VB.Timer timResize 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   480
      Top             =   720
   End
End
Attribute VB_Name = "frmToolbar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
  Move GetSetting("Pippo", "tlbPippo", "Left", Rnd * Screen.Width), _
       GetSetting("Pippo", "tlbPippo", "Top", Rnd * Screen.Height), _
       GetSetting("Pippo", "tlbPippo", "Width", 3000), _
       GetSetting("Pippo", "tlbPippo", "Height", 100)
  If Left + Width <= 0 Then Left = 0
  If Top + Height <= 0 Then Top = 0
  If Left >= Screen.Width Then Left = Screen.Width - Width
  If Top >= Screen.Height Then Top = Screen.Height - Height
 
  Toolbar1.ImageList = ilsPulsanti
  Dim b As Button
  Set b = Toolbar1.Buttons.Add(, "cmd1", , tbrDefault, "cmd1")
  b.ToolTipText = "cmd1": b.Description = b.ToolTipText
  Set b = Toolbar1.Buttons.Add(, "cmd2", , tbrDefault, "cmd2")
  b.ToolTipText = "cmd2": b.Description = b.ToolTipText
  Toolbar1.Buttons.Add , , , tbrSeparator
  Set b = Toolbar1.Buttons.Add(, "cmd3", , tbrDefault, "cmd3")
  b.ToolTipText = "cmd3": b.Description = b.ToolTipText
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  SaveSetting "Pippo", "tlbPippo", "Left", Left
  SaveSetting "Pippo", "tlbPippo", "Top", Top
  SaveSetting "Pippo", "tlbPippo", "Width", Width
  SaveSetting "Pippo", "tlbPippo", "Height", Height
End Sub
Private Sub Form_Resize()
  timResize.Enabled = True
End Sub
Private Sub timResize_Timer()
  Dim XMax As Single, YMax As Single, b As Button
 
  timResize.Enabled = False
 
  For Each b In Toolbar1.Buttons
    If b.Style <> tbrPlaceholder And b.Style <> tbrSeparator Then
      If b.Left + b.Width > XMax Then XMax = b.Left + b.Width
      If b.Top + b.Height > YMax Then YMax = b.Top + b.Height
    End If
  Next b
  Me.Move Me.Left, Me.Top, Me.Width - Me.ScaleWidth + XMax, Me.Height -
Me.ScaleHeight + YMax + 30
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
  Select Case Button.Key
    Case "cmd1": Cmd1
    Case "cmd2": Cmd2
    Case "cmd3": Cmd3
    Case Else: Stop
  End Select
End Sub

...
