How do I create a right-aligned toolbar button?

I didn't think this was all that common a request, but it came in twice from two different customers, so I guess there are still people creating toolbars, and creating them with right-aligned buttons (even though it violates Windows user interface guidelines, though I can't find a citation right now).

You may have noticed that the toolbar common control doesn't provide a facility for creating right-aligned buttons. Partly because it's a violation of the guidelines anyway, but mostly because the default state of every feature is "not implemented." Adding a feature requires work, and since there is only a finite amount of work available to apply, you have to decide where to spend it. And generally speaking, you don't focus your efforts on helping people violate the guidelines.

If you want to create a right-aligned toolbar button, you can cobble one together by combining things you already have. I can think of two ways of doing this off the top of my head.

  • Create two toolbars, one for the left-aligned buttons and one for the right-aligned buttons, then size and position them appropriately.
  • Create a separator between the left-aligned buttons and the right-aligned buttons, and set the separator size appropriately.

Which comes to a third reason why there is no feature for right-aligned toolbar buttons: Because you can already do it yourself without too much effort.

Comments (9)
  1. Roman says:

    (even though it violates Windows user interface guidelines, though I can't find a citation right now)

    Here's what I found:

    Display toolbar buttons left aligned. The Help icon, if present, is right aligned.

    (Picture: All toolbar buttons are left aligned except for Help.)

    Exception: Windows 7-style toolbars left align program specific commands, but right align standard, well-known commands such as Options, View, and Help.…/aa511500.aspx

  2. Adam Rosenfield says:

    What if all the buttons were right-aligned and the application was in a language with a right-to-left reading order?  Well, it's just a guideline (even if [citation needed]), not a hard-and-fast rule, so that's probably a reasonable situation in which to deviate from the guideline.  Of course, using mixed left-aligned and right-aligned buttons, that's a whole other story.

  3. Dan Bugglin says:

    @Roman I was going to call out Office 2007 for having a right aligned toolbar button, but it is in fact the Help button so I suppose it followed the guidelines then (and I guess it's not really a toolbar if it just has one button, too).

    @Adam Rosenfield In an RTL language toolbars are flipped, so anything right aligned would end up on the left, as expected.

    It's a bit confusing, some toolkits use the terms "Near" and "Far" instead to be LTR/RTL neutral.

  4. Adrian says:

    Some people use Toolbars disguised as menu bars (text only without icons).  Menu bar items support MFT_RIGHTJUSTIFY, which was once commonly used to push the Help menu off to the right side of the menu bar.

    The resource compiler still allows the HELP option on a menu bar item.  This used to map to MFT_RIGHTJUSTIFY, but I think it's a no-op in more recent versions.

    On one project I worked on, debug builds had a special Debug menu with MFT_RIGHTJUSTIFY to make it clear it wasn't part of the normal product.

    A lot of Windows 7 toolbars (like the one in the basic Explorer view) seem to be pushing some toolbar items off to the right side.

  5. WndSks says:

    @Adrian: MS started that trend with IE4 (and the shell update for win95) IIRC, they even have a guide…/bb775450(v=vs.85).aspx

  6. jon says:

    @The MAZZTer: The Windows user interface guidelines definitely do not apply to Office.

  7. Troll says:

    "I guess there are still people creating toolbars". That's because the people on the shell team removed customizability from Explorer toolbars. Or the floating toolbars on the desktop. Or the image toolbar from IE. Or the toolbars from Office.

  8. Still creating toolbars says:

    Three cheers for the old Office Shortcut Bar :-)

  9. Amnesia says:

    As there are languages you read from right to left, I suppose the customers was looking for a full right-to-left application. No ?

    [No, they wanted some left-aligned buttons and some right-aligned buttons. The RTL case is handled automatically. (To use proper layout terminology, they were looking for "far-aligned toolbar buttons", but if I had written that, nobody reading the article would know what I was talking about.) -Raymond]

Comments are closed.

Skip to main content