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?
As far as I'm aware, and according to the msdn docs, SetButtonInfo only sets the width of a separator. For all other types it sets the index of the image to use.
As far as I'm aware, and according to the msdn docs, SetButtonInfo only sets the width of a separator. For all other types it sets the index of the image to use.
I pointed out that you should try CToolBarCtrl::SetButtonInfo method, not a CToolBar::SetButtonInfo
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?
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?
You don't need to derive.
But if you want to - what is the problem?
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.
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.
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).
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.