News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How do I right-align a button on a toolbar?

By Joao Paulo Figueira, January 21, 2004.
Print version

Question

Toolbar buttons are always inserted from the left to the right. How can I insert buttons that are right aligned?

Answer

After you've seen it working, it is actually quite simple. All we need to do is to insert an empty filler toolbar button with the appropriate size, so that all buttons to its right will be right-aligned.

To illustrate this technique, I've derived a class from CCeCommandBar that enables this functionality. To use it (check the sample application), load all the buttons in the command bar and call RightAlign using the ID of the first button you want to right-align. All the buttons to its right will be right-aligned.

m_wndCommandBar.RightAlign(ID_APP_ABOUT);

How it works

The RightAlign method works by inserting an inactive button to the left of the button group you want to right-align. Next, its size is calculated and set so that the button group is moved to the right of the command bar.

This sample shows how to handle the SIP button, in case it is visible (most of the time). This button will overlap with the command bar, so you must adjust its size, otherwise the rightmost button will be hidden.

Finally, this code can be easily adapted to a CToolBar-derived class: just remove the SIP logic!

And that's it.

Sample

You can download a sample here - RightAlign.zip (33K).

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House