Solved

Align toolbar button in the middle

Posted on 2006-07-21
4
617 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 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

18 Experts available now in Live!

Get 1:1 Help Now