ButtonBase.Image 属性

获取或设置显示在按钮控件上的图像。

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

语法

声明
<LocalizableAttribute(True)> _
Public Property Image As Image
用法
Dim instance As ButtonBase
Dim value As Image

value = instance.Image

instance.Image = value
[LocalizableAttribute(true)] 
public Image Image { get; set; }
[LocalizableAttribute(true)] 
public:
property Image^ Image {
    Image^ get ();
    void set (Image^ value);
}
/** @property */
public Image get_Image ()

/** @property */
public void set_Image (Image value)
public function get Image () : Image

public function set Image (value : Image)

属性值

按钮控件上显示的 Image。默认值为 空引用(在 Visual Basic 中为 Nothing)。

备注

设置 Image 属性后,ImageList 属性将被设置为 空引用(在 Visual Basic 中为 Nothing),而 ImageIndex 属性被设置为其默认值 -1。

提示

如果 FlatStyle 属性设置为 FlatStyle.System,则分配给 Image 属性的任何图像都不会显示。

示例

下面的代码示例使用派生类 Button 并设置它的一些通用属性。结果将是一个平面按钮,它的左边有文本,右边有图像。这段代码要求您有一个存储在 C:\Graphics 目录中的位图图像 MyBitMap.bmp,并包含了对 System.Drawing 命名空间的一个引用。

Private Sub SetMyButtonProperties()
    ' Assign an image to the button.
    button1.Image = Image.FromFile("C:\Graphics\MyBitmap.bmp")
    ' Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight
    button1.TextAlign = ContentAlignment.MiddleLeft
    ' Give the button a flat appearance.
    button1.FlatStyle = FlatStyle.Flat
End Sub 'SetMyButtonProperties
private void SetMyButtonProperties()
 {
    // Assign an image to the button.
    button1.Image = Image.FromFile("C:\\Graphics\\MyBitmap.bmp");
    // Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight;    
    button1.TextAlign = ContentAlignment.MiddleLeft;
    // Give the button a flat appearance.
    button1.FlatStyle = FlatStyle.Flat;
 }
 
private:
   void SetMyButtonProperties()
   {
      // Assign an image to the button.
      button1->Image = Image::FromFile( "C:\\Graphics\\MyBitmap.bmp" );
      // Align the image and text on the button.
      button1->ImageAlign = ContentAlignment::MiddleRight;
      button1->TextAlign = ContentAlignment::MiddleLeft;
      // Give the button a flat appearance.
      button1->FlatStyle = FlatStyle::Flat;
   }
private void SetMyButtonProperties()
{
    // Assign an image to the button.
    button1.set_Image(Image.FromFile("C:\\Graphics\\MyBitmap.bmp"));

    // Align the image and text on the button.
    button1.set_ImageAlign(ContentAlignment.MiddleRight);
    button1.set_TextAlign(ContentAlignment.MiddleLeft);

    // Give the button a flat appearance.
    button1.set_FlatStyle(FlatStyle.Flat);
} //SetMyButtonProperties
private function SetMyButtonProperties()
 {
    // Assign an image to the button.
    button1.Image = Image.FromFile("C:\\Graphics\\MyBitmap.bmp");
    // Align the image and text on the button.
    button1.ImageAlign = ContentAlignment.MiddleRight;    
    button1.TextAlign = ContentAlignment.MiddleLeft;
    // Give the button a flat appearance.
    button1.FlatStyle = FlatStyle.Flat;
 }
 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、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

请参见

参考

ButtonBase 类
ButtonBase 成员
System.Windows.Forms 命名空间
ImageList
ButtonBase.FlatStyle 属性