指定したツール バー ボタンがコレクションのメンバかどうかを確認します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
'宣言
Public Function Contains ( _
button As ToolBarButton _
) As Boolean
'使用
Dim instance As ToolBarButtonCollection
Dim button As ToolBarButton
Dim returnValue As Boolean
returnValue = instance.Contains(button)
public bool Contains (
ToolBarButton button
)
public:
bool Contains (
ToolBarButton^ button
)
public boolean Contains (
ToolBarButton button
)
public function Contains (
button : ToolBarButton
) : boolean
パラメータ
- button
コレクション内で検索する ToolBarButton。
戻り値
ToolBarButton がコレクションのメンバの場合は true。それ以外の場合は false。
解説
このメソッドを使用すると、ToolBarButton に対して操作を実行する前に、ToolBarButton がコレクションのメンバかどうかを確認できます。このメソッドを使用して、ToolBarButton がコレクションに追加されたことや、依然としてコレクションのメンバであることを確認できます。
使用例
存在する場合は ToolBar コントロールから既存の ToolBarButton を削除し、ToolBar に新しい 4 つの ToolBarButton オブジェクトを追加して挿入するコード例を次に示します。この例では、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
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
ToolBar.ToolBarButtonCollection クラス
ToolBar.ToolBarButtonCollection メンバ
System.Windows.Forms 名前空間