ToolBar.ImageList 属性
获取或设置工具栏按钮控件的可用图像集合。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public Property ImageList As ImageList
用法
Dim instance As ToolBar
Dim value As ImageList
value = instance.ImageList
instance.ImageList = value
public ImageList ImageList { get; set; }
public:
property ImageList^ ImageList {
ImageList^ get ();
void set (ImageList^ value);
}
/** @property */
public ImageList get_ImageList ()
/** @property */
public void set_ImageList (ImageList value)
public function get ImageList () : ImageList
public function set ImageList (value : ImageList)
属性值
一个 ImageList,它包含 ToolBarButton 控件可用的图像。默认为 空引用(在 Visual Basic 中为 Nothing)。
备注
如果创建一个 ImageList 并将其分配给 ImageList 属性,则可通过将集合中某个图像的索引值分配给工具栏按钮的 ImageIndex 属性,将该图像分配给 ToolBarButton 控件。
示例
下面的代码示例创建一个 ToolBar 控件,设置它的一些公共属性,并将它添加到 Form。还将委托添加到 ButtonClick 和 ButtonDropDown 事件。本示例要求已经声明一个名为 toolBar1
的 ToolBar 和一个名为 imageList1
的 ImageList。
Private Sub AddToolBar()
' Add a toolbar and set some of its properties.
toolBar1 = New ToolBar()
toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.None
toolBar1.Buttons.Add(Me.toolBarButton1)
toolBar1.ButtonSize = New System.Drawing.Size(24, 24)
toolBar1.Divider = True
toolBar1.DropDownArrows = True
toolBar1.ImageList = Me.imageList1
toolBar1.ShowToolTips = True
toolBar1.Size = New System.Drawing.Size(292, 25)
toolBar1.TabIndex = 0
toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right
toolBar1.Wrappable = False
' Add handlers for the ButtonClick and ButtonDropDown events.
AddHandler toolBar1.ButtonDropDown, AddressOf toolBar1_ButtonDropDown
AddHandler toolBar1.ButtonClick, AddressOf toolBar1_ButtonClicked
' Add the toolbar to the form.
Me.Controls.Add(toolBar1)
End Sub
private void AddToolBar()
{
// Add a toolbar and set some of its properties.
toolBar1 = new ToolBar();
toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.None;
toolBar1.Buttons.Add(this.toolBarButton1);
toolBar1.ButtonSize = new System.Drawing.Size(24, 24);
toolBar1.Divider = true;
toolBar1.DropDownArrows = true;
toolBar1.ImageList = this.imageList1;
toolBar1.ShowToolTips = true;
toolBar1.Size = new System.Drawing.Size(292, 25);
toolBar1.TabIndex = 0;
toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
toolBar1.Wrappable = false;
// Add handlers for the ButtonClick and ButtonDropDown events.
toolBar1.ButtonDropDown +=
new ToolBarButtonClickEventHandler(toolBar1_ButtonDropDown);
toolBar1.ButtonClick +=
new ToolBarButtonClickEventHandler(toolBar1_ButtonClicked);
// Add the toolbar to the form.
this.Controls.Add(toolBar1);
}
void AddToolBar()
{
// Add a toolbar and set some of its properties.
toolBar1 = gcnew ToolBar;
toolBar1->Appearance = System::Windows::Forms::ToolBarAppearance::Flat;
toolBar1->BorderStyle = System::Windows::Forms::BorderStyle::None;
toolBar1->Buttons->Add( this->toolBarButton1 );
toolBar1->ButtonSize = System::Drawing::Size( 24, 24 );
toolBar1->Divider = true;
toolBar1->DropDownArrows = true;
toolBar1->ImageList = this->imageList1;
toolBar1->ShowToolTips = true;
toolBar1->Size = System::Drawing::Size( 292, 25 );
toolBar1->TabIndex = 0;
toolBar1->TextAlign = System::Windows::Forms::ToolBarTextAlign::Right;
toolBar1->Wrappable = false;
// Add handlers for the ButtonClick and ButtonDropDown events.
toolBar1->ButtonDropDown += gcnew ToolBarButtonClickEventHandler( this, &MyToolBar::toolBar1_ButtonDropDown );
toolBar1->ButtonClick += gcnew ToolBarButtonClickEventHandler( this, &MyToolBar::toolBar1_ButtonClicked );
// Add the toolbar to the form.
this->Controls->Add( toolBar1 );
}
private void AddToolBar()
{
// Add a toolbar and set some of its properties.
toolBar1 = new ToolBar();
toolBar1.set_Appearance(System.Windows.Forms.ToolBarAppearance.Flat);
toolBar1.set_BorderStyle(System.Windows.Forms.BorderStyle.None);
toolBar1.get_Buttons().Add(this.toolBarButton1);
toolBar1.set_ButtonSize(new System.Drawing.Size(24, 24));
toolBar1.set_Divider(true);
toolBar1.set_DropDownArrows(true);
toolBar1.set_ImageList(this.imageList1);
toolBar1.set_ShowToolTips(true);
toolBar1.set_Size(new System.Drawing.Size(292, 25));
toolBar1.set_TabIndex(0);
toolBar1.set_TextAlign(System.Windows.Forms.ToolBarTextAlign.Right);
toolBar1.set_Wrappable(false);
// Add handlers for the ButtonClick and ButtonDropDown events.
toolBar1.add_ButtonDropDown(new ToolBarButtonClickEventHandler
(toolBar1_ButtonDropDown));
toolBar1.add_ButtonClick(new ToolBarButtonClickEventHandler
(toolBar1_ButtonClicked));
// Add the toolbar to the form.
this.get_Controls().Add(toolBar1);
} //AddToolBar
平台
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 类
ToolBar 成员
System.Windows.Forms 命名空间
ImageList 类
ToolBarButton