閱讀英文

共用方式為


ToolboxBitmapAttribute 建構函式

定義

初始化新的 ToolboxBitmapAttribute 物件。

多載

ToolboxBitmapAttribute(String)

使用來自指定檔案的影像,初始化新的 ToolboxBitmapAttribute 物件。

ToolboxBitmapAttribute(Type)

根據指定組件中內嵌為資源的 16 x 16 點陣圖,初始化新的 ToolboxBitmapAttribute 物件。

ToolboxBitmapAttribute(Type, String)

根據指定組件中內嵌為資源的 16 x 16 點陣圖,初始化新的 ToolboxBitmapAttribute 物件。

ToolboxBitmapAttribute(String)

來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs

使用來自指定檔案的影像,初始化新的 ToolboxBitmapAttribute 物件。

public ToolboxBitmapAttribute (string imageFile);

參數

imageFile
String

含有 16 x 16 點陣圖的檔案的名稱。

範例

下列程式代碼範例示範如何使用 建 ToolboxBitmapAttribute 構函式,將 設定 stop.bmp 為 的 StopSignControl工具箱圖示。 此範例假設有名為 stop.bmp c:\的 16 x 16 像素點陣圖。

[System.Drawing.ToolboxBitmap("c:\\stop.bmp")]
public class StopSignControl:
    System.Windows.Forms.UserControl

{
    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Button Button1;

    public StopSignControl() : base()
    {        
        this.Label1 = new System.Windows.Forms.Label();
        this.Button1 = new System.Windows.Forms.Button();

        this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) 0));

        this.Label1.ForeColor = System.Drawing.Color.Red;
        this.Label1.Location = new System.Drawing.Point(24, 56);
        this.Label1.Name = "Label1";
        this.Label1.TabIndex = 0;
        this.Label1.Text = "Stop!";
        this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

        this.Button1.Enabled = false;
        this.Button1.Location = new System.Drawing.Point(56, 88);
        this.Button1.Name = "Button1";
        this.Button1.Size = new System.Drawing.Size(40, 32);
        this.Button1.TabIndex = 1;
        this.Button1.Text = "stop";

        this.Controls.Add(this.Button1);
        this.Controls.Add(this.Label1);
        this.Name = "StopSignControl";
    }

    private void StopSignControl_MouseEnter(object sender, System.EventArgs e)
    {

        Label1.Text.ToUpper();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, 
        System.Drawing.FontStyle.Bold);
        Button1.Enabled = true;
    }

    private void StopSignControl_MouseLeave(object sender, System.EventArgs e)
    {

        Label1.Text.ToLower();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, 
        System.Drawing.FontStyle.Regular);
        Button1.Enabled = false;
    }
}

適用於

ToolboxBitmapAttribute(Type)

來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs

根據指定組件中內嵌為資源的 16 x 16 點陣圖,初始化新的 ToolboxBitmapAttribute 物件。

public ToolboxBitmapAttribute (Type t);

參數

t
Type

Type,程式碼會在其定義組件中搜尋點陣圖資源。

範例

下列程式代碼範例示範如何使用 建 ToolboxBitmapAttribute 構函式,將按鈕控件的圖示設定為 UserControl 具名 StopSignControl3的工具箱圖示。

[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.Button))]
public class StopSignControl3:
    System.Windows.Forms.UserControl

{
    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Button Button1;

    public StopSignControl3() : base()
    {        
        this.Label1 = new System.Windows.Forms.Label();
        this.Button1 = new System.Windows.Forms.Button();

        this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 
            12.0F, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point, ((byte) 0));
        this.Label1.ForeColor = System.Drawing.Color.Red;
        this.Label1.Location = new System.Drawing.Point(24, 56);
        this.Label1.Name = "Label1";
        this.Label1.TabIndex = 0;
        this.Label1.Text = "Stop!";
        this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

        this.Button1.Enabled = false;
        this.Button1.Location = new System.Drawing.Point(56, 88);
        this.Button1.Name = "Button1";
        this.Button1.Size = new System.Drawing.Size(40, 32);
        this.Button1.TabIndex = 1;
        this.Button1.Text = "stop";
        this.Controls.Add(this.Button1);
        this.Controls.Add(this.Label1);
        this.Name = "StopSignControl";
    }

    private void StopSignControl_MouseEnter(object sender, System.EventArgs e)
    {
        Label1.Text.ToUpper();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily,
        14.0F, System.Drawing.FontStyle.Bold);
        Button1.Enabled = true;
    }

    private void StopSignControl_MouseLeave(object sender, System.EventArgs e)
    {
        Label1.Text.ToLower();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 
        12.0F, System.Drawing.FontStyle.Regular);
        Button1.Enabled = false;
    }
}

備註

此建構函式會搜尋元件中定義 參數所 t 指定類型的內嵌資源。 建構函式會搜尋名為 namespace.classname.bmp 的資源,其中 namespace 是包含 參數所 t 指定類別定義的命名空間。 例如,如果 ControlA 位於 AssemblyA.dll 中的 NamespaceA,則建構函式會搜尋 AssemblyA.dll 名為 NamespaceA.ControlA.bmp 的資源。

適用於

ToolboxBitmapAttribute(Type, String)

來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs
來源:
ToolboxBitmapAttribute.cs

根據指定組件中內嵌為資源的 16 x 16 點陣圖,初始化新的 ToolboxBitmapAttribute 物件。

public ToolboxBitmapAttribute (Type t, string name);

參數

t
Type

Type,程式碼會在其定義組件中搜尋點陣圖資源。

name
String

內嵌點陣圖資源的名稱。

範例

'下列程式代碼範例示範如何使用 建 ToolboxBitmapAttribute 構函式,將 設定 StopSignControl2.bmp 為 的 StopSignControl2工具箱圖示。 此範例假設有名為 StopSignControl2.bmp 的 16 x 16 像素位圖,其 BuildAction 屬性設定為 EmbeddedResource

[System.Drawing.ToolboxBitmap(typeof(StopSignControl2), "StopSignControl2.bmp")]
public class StopSignControl2:
    System.Windows.Forms.UserControl

{
    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Button Button1;

    public StopSignControl2() : base()
    {        
        this.Label1 = new System.Windows.Forms.Label();
        this.Button1 = new System.Windows.Forms.Button();

        this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 
            12.0F, System.Drawing.FontStyle.Regular, 
            System.Drawing.GraphicsUnit.Point, ((byte) 0));
        this.Label1.ForeColor = System.Drawing.Color.Red;
        this.Label1.Location = new System.Drawing.Point(24, 56);
        this.Label1.Name = "Label1";
        this.Label1.TabIndex = 0;
        this.Label1.Text = "Stop!";
        this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        this.Button1.Enabled = false;
        this.Button1.Location = new System.Drawing.Point(56, 88);
        this.Button1.Name = "Button1";
        this.Button1.Size = new System.Drawing.Size(40, 32);
        this.Button1.TabIndex = 1;
        this.Button1.Text = "stop";
        this.Controls.Add(this.Button1);
        this.Controls.Add(this.Label1);
        this.Name = "StopSignControl";
    }

    private void StopSignControl_MouseEnter(object sender, System.EventArgs e)
    {
        Label1.Text.ToUpper();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, 
            System.Drawing.FontStyle.Bold);
        Button1.Enabled = true;
    }

    private void StopSignControl_MouseLeave(object sender, System.EventArgs e)
    {

        Label1.Text.ToLower();
        Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, 
        System.Drawing.FontStyle.Regular);
        Button1.Enabled = false;
    }
}

備註

此建構函式會搜尋元件中定義 參數所 t 指定類型的內嵌資源。 建構函式會搜尋名為 namespace.name 的資源,其中namespace是包含參數所 t 指定類別定義的命名空間。 例如,假設 ControlA 是 namespaceA 中的類別,AssemblyA.dll,且您已將 “MyBitmap.bmp” name 傳遞給 參數。 然後建構函式會搜尋 AssemblyA.dll 名為 NamespaceA.MyBitmap.bmp 的資源。

適用於