If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Toolbar button sizes

I've created a toolbar that has text to the right of the icon using the TBSTYLE_LIST style and added text to a button using SetButtonText(). Initially, the button size is not changed to reflect the fact that there is now text on the button. Various pages online solve this by using SetSizes on the toolbar to set the button size correctly.

My problem is that this sets all the button sizes to the same width. Only the first two buttons on my toolbar have text, the others I want to only have icons.

Is there a way to set the size (width) for individual buttons on the toolbar?

Re: Toolbar button sizes

My mistake. So to use this I'll have to derive from CToolBar and add some functions to set the button sizes. Is there a good place to do this such that all button size according to text width? Perhaps CToolBar::OnSize?

Re: Toolbar button sizes

Originally Posted by rioch

My mistake. So to use this I'll have to derive from CToolBar and add some functions to set the button sizes. Is there a good place to do this such that all button size according to text width? Perhaps CToolBar::OnSize?

Re: Toolbar button sizes

I've created the toolbar using the style TBSTYLE_LIST. I've tried the code below, but neither the text appears nor the button size changes. If I remove the text from the buttonInfo and set it instead with m_wndToolBar1.SetButtonText() the text appears (to the right) but all the buttons take the same width again - in fact, in this case, it chops off the end of the toolbar.

Re: Toolbar button sizes

It seems I needed the flat TBIF_BYINDEX. However, this only works correctly if I don't set the text. If I set the text (either method) it causes all buttons to change size. It even pushes other controls on the toolbar past the edge (the toolbar itself doesn't resize along with the button).

The TBSTYLE_EX_MIXEDBUTTONS style allows optional text on buttons. The BTNS_SHOWTEXT shows it for that button. The only problem now is that a combo box which has been added after this button is being clipped by the end on the toolbar.

Re: Toolbar button sizes

RecalcLayout didn't help. Let me explain some more.

I have a toolbar which has three buttons and a combo box. All the buttons have an icon, the first button also has text to the right of the icon. The combo box is added by calling SetButtonInfo on the toolbar (replacing a separator).

If I do not have text on the first button, everything fits nicely in the toolbar. If I add text, everything moves along to accomodate the text in the button, but the toolbar doesn't grow in width. The result is that the combobox is cut off at the end (see attached screenshot).