Solved

Align toolbar button in the middle

Posted on 2006-07-21
4
613 Views
Last Modified: 2008-03-03
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
Comment
Question by:nauman_ahmed
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 500 total points
ID: 17157884
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
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 17168047
Thanks a lot Rob, it worked perfectly. I have one more question: How can I display a drop-down in the toolbar?

-Nauman.
0
 
LVL 25

Author Comment

by:nauman_ahmed
ID: 17168069
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
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 17168197
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now