?
Solved

Align toolbar button in the middle

Posted on 2006-07-21
4
Medium Priority
?
630 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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