先在工具箱中双击ToolBal控件
然后在属性窗口中找到Buttons,点击旁边的按钮
弹出对话框后,点击添加即可添加在工具栏中的按钮
再修改各个属性即可若要在按钮上加上图片,首先要添加一个ImageList控件,在选中Image属性添加图片
然后选择工具条属性中的Imagelis属性,在下拉菜单中选中刚刚创建的ImageList控件名即可

解决方案 »

  1.   

    刚刚你说:然后选择工具条属性中的Imagelis属性,在下拉菜单中选中刚刚创建的ImageList控件名即可.
    可是那么多的按钮和那么多的图片,怎么一一对应?
      

  2.   

    还要回到工具条属性的Buttons属性,在里面选中每个按钮的ImageIndex属性,在下拉菜单
    有你刚才在ImageList控件中添加的图片,选择即可
      

  3.   

    ToolBar 控件用于显示可显示为标准按钮、切换式按钮或下拉式按钮的 ToolBarButton 控件。可以为按钮分配图像,方法是实例化一个 ImageList 对象,将它分配给工具栏的 ImageList 属性,然后将图像索引值分配给每个 ToolBarButton 按钮的 ImageIndex 属性。然后可以通过设置 ToolBarButton 的 Text 属性,将文本指定为显示在图像的下方或右边。将工具栏的 Appearance 属性设置为 ToolBarAppearance.Flat,为工具栏及其按钮赋予平面外观。当鼠标指针移动到按钮上时,按钮的外观变为三维样式。通过使用分隔符可以将工具栏按钮划分成多个逻辑组。分隔符是 Style 属性设置为 ToolBarButtonStyle.Separator 的工具栏按钮。当工具栏具有平面外观时,按钮之间的按钮分隔符将显示为线,而不是间隔。如果将 Appearance 属性设置为 ToolBarAppearance.Normal,则工具栏按钮的外观呈现凸起和三维的效果。如果没有设置 ButtonSize,默认情况下,将在类中计算一个 Size 对象以设置它。计算所得的大小将容纳分配给 ToolBarButton 控件的最大图像和文本。若要创建将在 ToolBar 上显示的 ToolBarButton 控件的集合,请使用 Buttons 属性的 Add 或 Insert 方法逐个添加这些按钮。示例
    [Visual Basic, C#] 以下示例实例化一个 ToolBar 和三个 ToolBarButton 控件。这些工具栏按钮将被分配到按钮集合,该集合又被分配到工具栏,而工具栏将被添加到窗体上。当工具栏的 ButtonClick 事件发生时,将计算 ToolBarButtonClickEventArgs 的 Button 属性,并打开适当的对话框。此代码假定已经实例化一个 Form、一个 OpenFileDialog、一个 SaveFileDialog 和一个 PrintDialog。[Visual Basic] 
    Public Sub InitializeMyToolBar()
        ' Create and initialize the ToolBar and ToolBarButton controls.
        Dim toolBar1 As New ToolBar()
        Dim toolBarButton1 As New ToolBarButton()
        Dim toolBarButton2 As New ToolBarButton()
        Dim toolBarButton3 As New ToolBarButton()
        
        ' Set the Text properties of the ToolBarButton controls.
        toolBarButton1.Text = "Open"
        toolBarButton2.Text = "Save"
        toolBarButton3.Text = "Print"
        
        ' Add the ToolBarButton controls to the ToolBar.
        toolBar1.Buttons.Add(toolBarButton1)
        toolBar1.Buttons.Add(toolBarButton2)
        toolBar1.Buttons.Add(toolBarButton3)
        
        ' Add the event-handler delegate.
        AddHandler toolBar1.ButtonClick, AddressOf Me.toolBar1_ButtonClick
        
        ' Add the ToolBar to the Form.
        Controls.Add(toolBar1)
    End Sub    Protected Sub toolBar1_ButtonClick(sender As Object, _
        e As ToolBarButtonClickEventArgs)
        
        ' Evaluate the Button property to determine which button was clicked.
        Select Case toolBar1.Buttons.IndexOf(e.Button)
            Case 0
                openFileDialog1.ShowDialog()
                ' Insert code to open the file.
            Case 1
                saveFileDialog1.ShowDialog()
                ' Insert code to save the file.
            Case 2
                printDialog1.ShowDialog()
                ' Insert code to print the file.
        End Select        
    End Sub
    [C#] 
    public void InitializeMyToolBar()
     {
        // Create and initialize the ToolBar and ToolBarButton controls.
        toolBar1 = new ToolBar();
        ToolBarButton toolBarButton1 = new ToolBarButton();
        ToolBarButton toolBarButton2 = new ToolBarButton();
        ToolBarButton toolBarButton3 = new ToolBarButton();
     
        // Set the Text properties of the ToolBarButton controls.
        toolBarButton1.Text = "Open";
        toolBarButton2.Text = "Save";
        toolBarButton3.Text = "Print";
     
        // Add the ToolBarButton controls to the ToolBar.
        toolBar1.Buttons.Add(toolBarButton1);
        toolBar1.Buttons.Add(toolBarButton2);
        toolBar1.Buttons.Add(toolBarButton3);
        
        // Add the event-handler delegate.
        toolBar1.ButtonClick += new ToolBarButtonClickEventHandler (
           this.toolBar1_ButtonClick);
        
        // Add the ToolBar to the Form.
        Controls.Add(toolBar1);
     }
     
     protected void toolBar1_ButtonClick (
                             Object sender, 
                             ToolBarButtonClickEventArgs e)
     {
       // Evaluate the Button property to determine which button was clicked.
       switch(toolBar1.Buttons.IndexOf(e.Button))
       {
          case 0:
             openFileDialog1.ShowDialog();
             // Insert code to open the file.
             break; 
          case 1:
             saveFileDialog1.ShowDialog();
             // Insert code to save the file.
             break; 
          case 2:
             printDialog1.ShowDialog();
             // Insert code to print the file.    
             break; 
        }
     }
      

  4.   

    ToolBar 按钮中能够显示图标,目的是便于用户进行识别。这是通过以下操作实现的:向ImageList 组件添加图像,然后使 ImageList 组件与“工具栏”(ToolBar) 控件关联。以编程方式设置工具栏按钮的图标此示例假定已实例化一个 ImageList 组件和一个 ToolBar 控件,并且至少已向 ImageList 组件分配了一个图像。有关详细信息,请参阅 Image 类。 在过程中,实例化一个 ImageList 组件和一个 ToolBar 控件。 
    在同一过程中,向该 ImageList 组件分配一个图像。 
    在同一过程中,向该 ToolBar 控件分配 ImageList 控件,并分配单个工具栏按钮的 ImageIndex 属性。 
    按照上述步骤,您应该已经编写出类似于下面显示的代码。 ' Visual Basic
    Public Sub InitializeMyToolBar()
    ' Instantiate an ImageList component and a ToolBar control.
       Dim ToolBar1 as New ToolBar
       Dim ImageList1 as New ImageList
    ' Assign an image to the ImageList component.
    ' The image used below is for demonstration purposes only.
    ' Replace it with an image of your own choosing.
       Dim myImage As System.Drawing.Image = Image.FromFile("C:\winnt\Sample.ico")
       ImageList1.Images.Add(myImage)
    ' Create a ToolBarButton.
       Dim ToolBarButton1 As New ToolBarButton()
    ' Add the ToolBarButton to the ToolBar.
       ToolBar1.Buttons.Add(toolBarButton1)
    ' Assign an ImageList to the ToolBar.
       ToolBar1.ImageList = ImageList1
    ' Assign the ImageIndex property of the ToolBarButton.
       ToolBarButton1.ImageIndex = 0
    End Sub// C#
    public void InitializeMyToolBar()
    {
       // Instantiate an ImageList component and a ToolBar control.
       ToolBar toolBar1 = new  ToolBar(); 
       ImageList imageList1 = new ImageList();
       // Assign an image to the ImageList component.
       // The image used below is for demonstration purposes only.
       // Replace it with an image of your own choosing.
       Image myImage = Image.FromFile("C:\\winnt\\Sample.ico");
       ImageList1.Images.Add(myImage);
       // Create a ToolBarButton.
       ToolBarButton toolBarButton1 = new ToolBarButton();
       // Add the ToolBarButton to the ToolBar.
       toolBar1.Buttons.Add(toolBarButton1);
       // Assign an ImageList to the ToolBar.
       toolBar1.ImageList = imageList1;
       // Assign ImageIndex property of the ToolBarButton.
       toolBarButton1.ImageIndex = 0;
    }