• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Align toolbar button in the middle

I have a toolbar aligned in the bottom of an SDI form. I would like to center align the buttons added to this toolbar. How this can be done?

Thanks,
Nauman.
0
nauman_ahmed
Asked:
nauman_ahmed
  • 2
  • 2
1 Solution
 
Rob_JeffreyCommented:
If you create a single button before all others in the list, set its style to 4-tbrPlaceHolder and its width to half of the remaining space of the toolbar width minus the width of all other buttons, you should get what you are after.

Private Sub Form_Load()
    Toolbar1.Align = vbAlignBottom
    Toolbar1.Buttons.Add
    Toolbar1.Buttons(1).Style = tbrPlaceholder
    Toolbar1.Buttons.Add
    Toolbar1.Buttons.Add
End Sub

Private Sub Form_Paint()
    Dim a As Long
    Dim totalwidth As Long
    For a = 2 To Toolbar1.Buttons.Count
        totalwidth = totalwidth + Toolbar1.Buttons(a).Width
    Next
    Toolbar1.Buttons(1).Width = (Toolbar1.Width - totalwidth) / 2
End Sub
0
 
nauman_ahmedAuthor Commented:
Thanks a lot Rob, it worked perfectly. I have one more question: How can I display a drop-down in the toolbar?

-Nauman.
0
 
nauman_ahmedAuthor Commented:
Let me clarify it a little bit more. I have used the VB standard toolbar button and when I click on the button it displays the drop-down. What I would like to do is display a drop-down instead of the button.

-Nauman.
0
 
Rob_JeffreyCommented:
I don't know how to add a combobox to a standard toolbar - but this may be of help.
You can use VBs PopupMenu to pop up a user menu at any time (like the right click menu in Explorer).
If you set up a menu like this in the menu editor:

   Begin VB.Menu mnuPop
      Caption         =   "mnuPop"
      Visible         =   0   'False
      Begin VB.Menu mnuEdit
         Caption         =   "Edit"
      End
      Begin VB.Menu mnuDel
         Caption         =   "Delete"
      End
      Begin VB.Menu mnuC
         Caption         =   "c"
      End
   End


Then you can use this code:
Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
      If Button.Index = 3 Then
          PopupMenu mnuPop
      End If
End Sub


Not a combobox - but it may give the additional options to the user you are looking for.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now