ToolboxBitmapAttribute.GetImage 方法

定义

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

重载

GetImage(Object)

获取与此 Image 对象关联的小 ToolboxBitmapAttribute

GetImage(Type)

获取与此 Image 对象关联的小 ToolboxBitmapAttribute

GetImage(Object, Boolean)

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

GetImage(Type, Boolean)

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

GetImage(Type, String, Boolean)

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

GetImage(Object)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

获取与此 Image 对象关联的小 ToolboxBitmapAttribute

public:
 System::Drawing::Image ^ GetImage(System::Object ^ component);
public System.Drawing.Image GetImage (object component);
public System.Drawing.Image? GetImage (object? component);
member this.GetImage : obj -> System.Drawing.Image
Public Function GetImage (component As Object) As Image

参数

component
Object

如果此 ToolboxBitmapAttribute 对象尚没有小图像,则此方法在定义组件参数指定的对象类型的程序集中搜索位图资源。 例如,如果将类型为 ControlA 的对象传递给组件参数,则此方法在定义 ControlA 的程序集中搜索。

返回

与此 Image 对象关联的小 ToolboxBitmapAttribute

示例

下面的示例演示如何使用 GetImage 方法。

private:
    static Image^ GetImageOfCustomControl(Control^ userControl)
    {
        Image^ controlImage = nullptr;
        AttributeCollection^ attrCol =
            TypeDescriptor::GetAttributes(userControl);
        ToolboxBitmapAttribute^ imageAttr = (ToolboxBitmapAttribute^)
            attrCol[ToolboxBitmapAttribute::typeid];
        if (imageAttr != nullptr)
        {
            controlImage = imageAttr->GetImage(userControl);
        }

        return controlImage;
    }
private Image GetImageOfCustomControl(Control userControl)
{
    Image controlImage = null;
    AttributeCollection attrCol = 
            TypeDescriptor.GetAttributes(userControl);
    ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute)
        attrCol[typeof(ToolboxBitmapAttribute)];
    if (imageAttr != null)
    {
        controlImage = imageAttr.GetImage(userControl);
    }

    return controlImage;
}
Private Function GetImageOfCustomControl(ByVal userControl As Control) As Image 
    Dim controlImage As Image = Nothing
    Dim attrCol As AttributeCollection = TypeDescriptor.GetAttributes(userControl)
    Dim imageAttr As ToolboxBitmapAttribute = _
        CType(attrCol(GetType(ToolboxBitmapAttribute)), ToolboxBitmapAttribute)
    If (imageAttr IsNot Nothing) Then
        controlImage = imageAttr.GetImage(userControl)
    End If
    
    Return controlImage

End Function

注解

此方法搜索名为 namespace.classname.bmp 的资源,其中命名空间是包含 参数 component 指定的对象类型定义的命名空间。 例如,假设将 ControlA 类型的对象传递给 component 参数。 如果 ControlA 位于 AssemblyA.dll 中的 NamespaceA 中,则此方法 AssemblyA.dll 搜索名为 NamespaceA.ControlA.bmp 的资源。

适用于

GetImage(Type)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

获取与此 Image 对象关联的小 ToolboxBitmapAttribute

public:
 System::Drawing::Image ^ GetImage(Type ^ type);
public System.Drawing.Image GetImage (Type type);
public System.Drawing.Image? GetImage (Type type);
member this.GetImage : Type -> System.Drawing.Image
Public Function GetImage (type As Type) As Image

参数

type
Type

如果此 ToolboxBitmapAttribute 对象尚无小图像,则此方法在定义由类型参数指定的类型的程序集中搜索位图资源。 例如,如果将 typeof(ControlA) 传递给类型参数,则此方法在定义 ControlA 的程序集中搜索。

返回

与此 Image 对象关联的小 ToolboxBitmapAttribute

注解

此方法搜索名为 namespace.classname.bmp 的资源,其中命名空间是包含 参数 type 指定的类型的定义的命名空间。 例如,假设将 typeof (ControlA) 传递给 type 参数。 如果 ControlA 位于 AssemblyA.dll 中的 NamespaceA 中,则此方法 AssemblyA.dll 搜索名为 NamespaceA.ControlA.bmp 的资源。

适用于

GetImage(Object, Boolean)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

public:
 System::Drawing::Image ^ GetImage(System::Object ^ component, bool large);
public System.Drawing.Image GetImage (object component, bool large);
public System.Drawing.Image? GetImage (object? component, bool large);
member this.GetImage : obj * bool -> System.Drawing.Image
Public Function GetImage (component As Object, large As Boolean) As Image

参数

component
Object

如果此 ToolboxBitmapAttribute 对象尚没有小图像,则此方法在定义组件参数指定的对象类型的程序集中搜索位图资源。 例如,如果将类型为 ControlA 的对象传递给组件参数,则此方法在定义 ControlA 的程序集中搜索。

large
Boolean

指定此方法是返回大图像(true)还是小图像(false)。 小图像是 16 × 16,而大图像是 32 × 32。

返回

与此 Image 对象关联的 ToolboxBitmapAttribute 对象。

注解

此方法搜索名为 namespace.classname.bmp 的资源,其中命名空间是包含 参数 component 指定的对象类型定义的命名空间。 例如,假设将 ControlA 类型的对象传递给 component 参数。 如果 ControlA 位于 AssemblyA.dll 中的 NamespaceA 中,则此方法 AssemblyA.dll 搜索名为 NamespaceA.ControlA.bmp 的资源。

如果此 ToolboxBitmapAttribute 对象还没有大型图像,则此方法通过缩放小图像来创建大型图像。

适用于

GetImage(Type, Boolean)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

public:
 System::Drawing::Image ^ GetImage(Type ^ type, bool large);
public System.Drawing.Image GetImage (Type type, bool large);
public System.Drawing.Image? GetImage (Type type, bool large);
member this.GetImage : Type * bool -> System.Drawing.Image
Public Function GetImage (type As Type, large As Boolean) As Image

参数

type
Type

如果此 ToolboxBitmapAttribute 对象尚无小图像,则此方法在定义由组件类型指定的类型的程序集中搜索位图资源。 例如,如果将 typeof(ControlA) 传递给类型参数,则此方法在定义 ControlA 的程序集中搜索。

large
Boolean

指定此方法是返回大图像(true)还是小图像(false)。 小图像是 16 × 16,而大图像是 32 × 32。

返回

与此 Image 对象关联的 ToolboxBitmapAttribute

注解

此方法搜索名为 namespace.classname.bmp 的资源,其中命名空间是包含 参数 type 指定的类型的定义的命名空间。 例如,假设将 typeof (ControlA) 传递给 参数 type 。 如果 ControlA 位于 AssemblyA.dll 中的 NamespaceA 中,则此方法 AssemblyA.dll 搜索名为 NamespaceA.ControlA.bmp 的资源。

如果此 ToolboxBitmapAttribute 对象还没有大型图像,则此方法通过缩放小图像来创建大型图像。

适用于

GetImage(Type, String, Boolean)

Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs
Source:
ToolboxBitmapAttribute.cs

获取与此 Image 对象关联的小或大 ToolboxBitmapAttribute

public:
 System::Drawing::Image ^ GetImage(Type ^ type, System::String ^ imgName, bool large);
public System.Drawing.Image GetImage (Type type, string imgName, bool large);
public System.Drawing.Image? GetImage (Type type, string? imgName, bool large);
member this.GetImage : Type * string * bool -> System.Drawing.Image
Public Function GetImage (type As Type, imgName As String, large As Boolean) As Image

参数

type
Type

如果此 ToolboxBitmapAttribute 对象尚无小图像,则此方法将搜索嵌入的位图资源,搜索范围是在定义了由组件类型指定的类型的程序集中。 例如,如果将 typeof(ControlA) 传递给类型参数,则此方法在定义 ControlA 的程序集中搜索。

imgName
String

嵌入的位图资源的名称。

large
Boolean

指定此方法是返回大图像(true)还是小图像(false)。 小图像是 16 × 16,而大图像是 32 × 32。

返回

与此 Image 对象关联的 ToolboxBitmapAttribute

注解

此方法搜索名为 namespace.imgName 的资源,其中 namespace 是包含 参数指定的 type 类型的定义的命名空间。 例如,假设将 typeof (ControlA) 传递给 type 参数,并将“MyBitmap.bmp”传递给 imgName 参数。 如果 ControlA 位于 AssemblyA.dll 中的 NamespaceA 中,则此方法 AssemblyA.dll 搜索名为 NamespaceA.MyBitmap.bmp 的资源。

如果此 ToolboxBitmapAttribute 对象还没有大型图像,则此方法通过缩放小图像来创建大型图像。

适用于