BUG: Toolbar Buttons Show No Text or Images If ButtonSize and Font Properties Set After Buttons Added To Toolbar (327154)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition

This article was previously published under Q327154

SYMPTOMS

When you customize the buttons in a toolbar by changing the ButtonSize and Font properties of the toolbar control in the IDE, the text and images do not appear on the toolbar buttons at run time, although they appear correct at design time.

CAUSE

When you set the ButtonSize and Font properties after the ToolBar.Buttons.AddRange method is called, those properties do not take effect, and text and images do not appear on the buttons.

RESOLUTION

To work around this problem, follow these steps:
  1. Expand the "Windows Form Designer generated code" section in the code view of the form.
  2. Expand the private void InitializeComponent() method and look for a statement similar to the following:
    ToolBar.Buttons.AddRange(...);
    					
  3. Paste that statement of code at the end, after all of the properties of that ToolBar control have been set.
  4. Build and run the application.

    Note Because the IDE generates the code that causes the problem, any changes that you make in the IDE, such as adding new controls or events, cause the IDE to regenerate the code, so the statement that causes the problem returns to its original location. Therefore, every time that you build and test the application, check the code file to make sure that ToolBar.Buttons.AddRange(...); has been moved to the end.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Studio .NET, create a Microsoft Visual C# .NET Windows Application project.
  2. Drag a ToolBar control on the form.
  3. At the top of the Properties window, select the ToolBar control from the drop-down list.
  4. Select the Buttons property, and then click the ellipsis (...) button to open the ToolBarButton Collection Editor.
  5. Click Add to add a few buttons and add text for these buttons. Click OK to close the editor.
  6. In the Properties window of the ToolBar control, change the ButtonSize property to another size, and then change the Font property.
  7. Run the application. Notice that the buttons are blank.

Modification Type:MinorLast Reviewed:8/28/2005
Keywords:kbvs2002sp1sweep kbbug kbCtrl kbnofix kbToolbar KB327154