ToolBar.ToolBarButtonCollection.AddRange 方法

将一个工具栏按钮集合添加到此工具栏按钮集合中。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub AddRange ( _
    buttons As ToolBarButton() _
)
用法
Dim instance As ToolBarButtonCollection
Dim buttons As ToolBarButton()

instance.AddRange(buttons)
public void AddRange (
    ToolBarButton[] buttons
)
public:
void AddRange (
    array<ToolBarButton^>^ buttons
)
public void AddRange (
    ToolBarButton[] buttons
)
public function AddRange (
    buttons : ToolBarButton[]
)

参数

备注

包含在 nodes 数组中的 ToolBarButton 对象将附加到集合的末尾。

可以使用方法向集合迅速添加一组以前创建的 ToolBarButton 对象,而不必通过使用 Add 方法向集合手动添加每个 ToolBarButton

若要移除先前添加的 ToolBarButton,请使用 RemoveRemoveAtClear 方法。

示例

下面的代码示例从 ToolBar 控件中移除一个现有的 ToolBarButton(如果该按钮存在),并将四个新的 ToolBarButton 对象添加和插入到 ToolBar 中。本示例要求有一个在其上具有 ToolBar 控件的 Form

Private Sub AddToolbarButtons(toolBar As ToolBar)
   If Not toolBar.Buttons.IsReadOnly Then
      ' If toolBarButton1 in in the collection, remove it.
      If toolBar.Buttons.Contains(toolBarButton1) Then
         toolBar.Buttons.Remove(toolBarButton1)
      End If

      ' Create three toolbar buttons.
      Dim tbb1 As New ToolBarButton("tbb1")
      Dim tbb2 As New ToolBarButton("tbb2")
      Dim tbb3 As New ToolBarButton("tbb3")

      ' Add toolbar buttons to the toolbar.     
      toolBar.Buttons.AddRange(New ToolBarButton() {tbb2, tbb3})
      toolBar.Buttons.Add("tbb4")

      ' Insert tbb1 into the first position in the collection.
      toolBar.Buttons.Insert(0, tbb1)
   End If
End Sub
private void AddToolbarButtons(ToolBar toolBar)
{
   if(!toolBar.Buttons.IsReadOnly)
   {
      // If toolBarButton1 in in the collection, remove it.
      if(toolBar.Buttons.Contains(toolBarButton1))
      {
         toolBar.Buttons.Remove(toolBarButton1);
      }
    
      // Create three toolbar buttons.
      ToolBarButton tbb1 = new ToolBarButton("tbb1");
      ToolBarButton tbb2 = new ToolBarButton("tbb2");
      ToolBarButton tbb3 = new ToolBarButton("tbb3");
      
      // Add toolbar buttons to the toolbar.        
      toolBar.Buttons.AddRange(new ToolBarButton[] {tbb2, tbb3});
      toolBar.Buttons.Add("tbb4");
    
      // Insert tbb1 into the first position in the collection.
      toolBar.Buttons.Insert(0, tbb1);
   }
}
void AddToolbarButtons( ToolBar^ toolBar )
{
   if (  !toolBar->Buttons->IsReadOnly )
   {
      
      // If toolBarButton1 in in the collection, remove it.
      if ( toolBar->Buttons->Contains( toolBarButton1 ) )
      {
         toolBar->Buttons->Remove( toolBarButton1 );
      }
      
      // Create three toolbar buttons.
      ToolBarButton^ tbb1 = gcnew ToolBarButton( "tbb1" );
      ToolBarButton^ tbb2 = gcnew ToolBarButton( "tbb2" );
      ToolBarButton^ tbb3 = gcnew ToolBarButton( "tbb3" );
      
      // Add toolbar buttons to the toolbar.
      array<ToolBarButton^>^buttons = {tbb2,tbb3};
      toolBar->Buttons->AddRange( buttons );
      toolBar->Buttons->Add( "tbb4" );
      
      // Insert tbb1 into the first position in the collection.
      toolBar->Buttons->Insert( 0, tbb1 );
   }
}
private void AddToolbarButtons(ToolBar toolBar)
{
    if (!(toolBar.get_Buttons().get_IsReadOnly())) {
        // If toolBarButton1 in in the collection, remove it.
        if (toolBar.get_Buttons().Contains(toolBarButton1)) {
            toolBar.get_Buttons().Remove(toolBarButton1);
        }
        // Create three toolbar buttons.
        ToolBarButton tbb1 = new ToolBarButton("tbb1");
        ToolBarButton tbb2 = new ToolBarButton("tbb2");
        ToolBarButton tbb3 = new ToolBarButton("tbb3");
        // Add toolbar buttons to the toolbar.        
        toolBar.get_Buttons().AddRange(new ToolBarButton[] { tbb2, tbb3 });
        toolBar.get_Buttons().Add("tbb4");
        // Insert tbb1 into the first position in the collection.
        toolBar.get_Buttons().Insert(0, tbb1);
    }
} //AddToolbarButtons

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ToolBar.ToolBarButtonCollection 类
ToolBar.ToolBarButtonCollection 成员
System.Windows.Forms 命名空间
Add
Clear