CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    29

    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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Toolbar button sizes

    Try CToolBarCtrl::SetButtonInfo
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2008
    Posts
    29

    Re: Toolbar button sizes

    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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Toolbar button sizes

    Quote Originally Posted by rioch View Post
    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
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2008
    Posts
    29

    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?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Toolbar button sizes

    Quote Originally Posted by rioch View Post
    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?
    Victor Nijegorodov

  7. #7
    Join Date
    Dec 2008
    Posts
    29

    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.

    TBBUTTONINFO buttonInfo;
    buttonInfo.cbSize = sizeof(buttonInfo);
    buttonInfo.dwMask = TBIF_SIZE | TBIF_STYLE;
    buttonInfo.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;
    buttonInfo.cx = 150;
    buttonInfo.pszText = "Something...";
    m_wndToolBar1.GetToolBarCtrl().SetButtonInfo(1, &buttonInfo);

  8. #8
    Join Date
    Dec 2008
    Posts
    29

    Re: Toolbar button sizes

    Any help on this? I'm stumped.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured