Solved

Align toolbar button in the middle

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

730 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