ButtonBase.ImageAlign 属性

获取或设置按钮控件上的图像对齐方式。

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

语法

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

value = instance.ImageAlign

instance.ImageAlign = value
[LocalizableAttribute(true)] 
public ContentAlignment ImageAlign { get; set; }
[LocalizableAttribute(true)] 
public:
property ContentAlignment ImageAlign {
    ContentAlignment get ();
    void set (ContentAlignment value);
}
/** @property */
public ContentAlignment get_ImageAlign ()

/** @property */
public void set_ImageAlign (ContentAlignment value)
public function get ImageAlign () : ContentAlignment

public function set ImageAlign (value : ContentAlignment)

属性值

ContentAlignment 值之一。默认值为 MiddleCenter

异常

异常类型 条件

InvalidEnumArgumentException

分配的值不是 ContentAlignment 值之一。

示例

下面的代码示例使用派生类 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 命名空间
TextAlign