Icon 建構函式

定義

初始化 Icon 類別的新執行個體。

多載

Icon(Stream)

從指定的資料流,初始化 Icon 類別的新執行個體。

Icon(String)

從指定的檔案名稱初始化 Icon 類別的新執行個體。

Icon(Icon, Size)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

Icon(Stream, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

Icon(String, Size)

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

Icon(Type, String)

從指定的組件中的資源,初始化 Icon 類別的新執行個體。

Icon(Icon, Int32, Int32)

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

Icon(Stream, Int32, Int32)

使用指定的寬度和高度,從指定的資料流初始化 Icon 類別的新執行個體。

Icon(String, Int32, Int32)

使用來自指定檔案的指定寬度和高度,初始化 Icon 類別的新執行個體。

Icon(Stream)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

從指定的資料流,初始化 Icon 類別的新執行個體。

public:
 Icon(System::IO::Stream ^ stream);
public Icon (System.IO.Stream stream);
new System.Drawing.Icon : System.IO.Stream -> System.Drawing.Icon
Public Sub New (stream As Stream)

參數

stream
Stream

要從其中載入 Icon 的資料流。

例外狀況

stream 參數為 null

備註

圖示資源可以包含多個圖示影像。 一個圖示檔案可能包含數個大小和色彩深度的影像。 應用程式中使用的映像取決於作業系統和設定。 下列清單詳細說明圖示的典型大小:

  • 16 像素 x 16 像素

  • 32 像素 x 32 圖元

  • 48 像素 x 48 像素

這個建構函式會傳回指定數據流中包含的最小影像。

適用於

Icon(String)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

從指定的檔案名稱初始化 Icon 類別的新執行個體。

public:
 Icon(System::String ^ fileName);
public Icon (string fileName);
new System.Drawing.Icon : string -> System.Drawing.Icon
Public Sub New (fileName As String)

參數

fileName
String

要載入 Icon 的來源檔案。

備註

圖示資源可以包含多個圖示影像。 一個圖示檔案可能包含數個大小和色彩深度的影像。 應用程式中使用的映像取決於作業系統和設定。 下列清單詳細說明圖示的典型大小:

  • 16 像素 x 16 像素

  • 32 像素 x 32 圖元

  • 48 像素 x 48 像素

這個建構函式會傳回包含在指定檔案中的最小影像。

適用於

Icon(Icon, Size)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

public:
 Icon(System::Drawing::Icon ^ original, System::Drawing::Size size);
public Icon (System.Drawing.Icon original, System.Drawing.Size size);
new System.Drawing.Icon : System.Drawing.Icon * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (original As Icon, size As Size)

參數

original
Icon

要從其中載入已重新調整大小之圖示的 Icon

size
Size

Size 結構,指定新 Icon 的高度和寬度。

例外狀況

original 參數為 null

備註

如果找不到完全符合大小的版本,則會使用最接近的相符專案。 original如果 參數是Icon具有單一大小的 ,這個方法只會建立重複的圖示。 使用方法的 DrawImage 延展功能來調整圖示的大小。

適用於

Icon(Stream, Size)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

public:
 Icon(System::IO::Stream ^ stream, System::Drawing::Size size);
public Icon (System.IO.Stream stream, System.Drawing.Size size);
new System.Drawing.Icon : System.IO.Stream * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (stream As Stream, size As Size)

參數

stream
Stream

包含圖示資料的資料流。

size
Size

所需的圖示大小。

例外狀況

streamnull 或未包含影像資料。

適用於

Icon(String, Size)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

從指定的資料流,以指定之大小初始化 Icon 類別的新執行個體。

public:
 Icon(System::String ^ fileName, System::Drawing::Size size);
public Icon (string fileName, System.Drawing.Size size);
new System.Drawing.Icon : string * System.Drawing.Size -> System.Drawing.Icon
Public Sub New (fileName As String, size As Size)

參數

fileName
String

包含圖示資料之檔案的名稱和路徑。

size
Size

所需的圖示大小。

例外狀況

stringnull 或未包含影像資料。

備註

如果指定的檔案不包含符合所需大小的影像,則會傳回具有最接近大小的圖示。

fileName如果它不在目前的應用程式目錄中,則應該包含完整路徑。

適用於

Icon(Type, String)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

從指定的組件中的資源,初始化 Icon 類別的新執行個體。

public:
 Icon(Type ^ type, System::String ^ resource);
public Icon (Type type, string resource);
new System.Drawing.Icon : Type * string -> System.Drawing.Icon
Public Sub New (type As Type, resource As String)

參數

type
Type

Type,指定要在其中尋找資源的組件。

resource
String

要載入的資源名稱。

例外狀況

在包含指定之 resource 的組件中找不到 type 所指定的圖示。

範例

下列程式代碼範例示範如何使用 建 Icon 構函式。 若要執行此範例,請將程式代碼貼到 Windows Form 中,並處理表單的事件 PaintConstructAnIconFromATypePaint事件處理程式呼叫 方法,傳遞eEventArgs

private void ConstructAnIconFromAType(PaintEventArgs e)
{

    Icon icon1 = new Icon(typeof(Control), "Error.ico");
    e.Graphics.DrawIcon(icon1, new Rectangle(10, 10, 50, 50));
}
Private Sub ConstructAnIconFromAType(ByVal e As PaintEventArgs)

    Dim icon1 As New Icon(GetType(Control), "Error.ico")
    e.Graphics.DrawIcon(icon1, New Rectangle(10, 10, 50, 50))

End Sub

備註

這個建構函式會從資源建立 Icon ,其中包含 參數所type指定之型別的元件中的 參數所指定resource名稱。

這個建構函式會將指定型別的命名空間與資源的字串名稱結合在一起,並在元件指令清單中尋找相符專案。 例如,您可以傳入 Control 型別和 Error.ico 至這個建構函式,並尋找名為 System.Windows.Forms.Error.ico的資源。

適用於

Icon(Icon, Int32, Int32)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

初始化 Icon 類別的新執行個體,並嘗試尋找符合所要求大小的圖示版本。

public:
 Icon(System::Drawing::Icon ^ original, int width, int height);
public Icon (System.Drawing.Icon original, int width, int height);
new System.Drawing.Icon : System.Drawing.Icon * int * int -> System.Drawing.Icon
Public Sub New (original As Icon, width As Integer, height As Integer)

參數

original
Icon

要載入不同大小的來源圖示。

width
Int32

新圖示的寬度。

height
Int32

新圖示的高度。

例外狀況

original 參數為 null

範例

下列程式碼範例會示範如何使用 ToBitmap 方法。 此範例的設計目的是要與 Windows Forms 搭配使用。 Create 表單,並將下列程式代碼貼到窗體中。 IconToBitmap在表單的Paint事件處理程式中呼叫 方法,傳遞ePaintEventArgs

private:
   void IconToBitmap( PaintEventArgs^ e )
   {
      // Construct an Icon.
      System::Drawing::Icon^ icon1 = gcnew System::Drawing::Icon( SystemIcons::Exclamation,40,40 );

      // Call ToBitmap to convert it.
      Bitmap^ bmp = icon1->ToBitmap();

      // Draw the bitmap.
      e->Graphics->DrawImage( bmp, Point(30,30) );
   }
private void IconToBitmap(PaintEventArgs e)
{
    // Construct an Icon.
    Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

    // Call ToBitmap to convert it.
    Bitmap bmp = icon1.ToBitmap();

    // Draw the bitmap.
    e.Graphics.DrawImage(bmp, new Point(30, 30));
}
Private Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)

    ' Call ToBitmap to convert it.
    Dim bmp As Bitmap = icon1.ToBitmap()

    ' Draw the bitmap.
    e.Graphics.DrawImage(bmp, New Point(30, 30))
End Sub

備註

如果找不到完全符合大小的版本,則會使用最接近的相符專案。 original如果 參數是Icon具有單一大小的 ,這個方法只會建立重複的圖示。 使用方法的 DrawImage 延展功能來調整圖示的大小。

適用於

Icon(Stream, Int32, Int32)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

使用指定的寬度和高度,從指定的資料流初始化 Icon 類別的新執行個體。

public:
 Icon(System::IO::Stream ^ stream, int width, int height);
public Icon (System.IO.Stream stream, int width, int height);
new System.Drawing.Icon : System.IO.Stream * int * int -> System.Drawing.Icon
Public Sub New (stream As Stream, width As Integer, height As Integer)

參數

stream
Stream

要從其中載入圖示的資料流。

width
Int32

圖示的寬度,以像素為單位。

height
Int32

圖示的高度,以像素為單位。

例外狀況

stream 參數為 null

適用於

Icon(String, Int32, Int32)

來源:
Icon.cs
來源:
Icon.cs
來源:
Icon.cs

使用來自指定檔案的指定寬度和高度,初始化 Icon 類別的新執行個體。

public:
 Icon(System::String ^ fileName, int width, int height);
public Icon (string fileName, int width, int height);
new System.Drawing.Icon : string * int * int -> System.Drawing.Icon
Public Sub New (fileName As String, width As Integer, height As Integer)

參數

fileName
String

包含 Icon 資料之檔案的名稱和路徑。

width
Int32

Icon 的所需寬度。

height
Int32

Icon 的所需高度。

例外狀況

stringnull 或未包含影像資料。

備註

如果指定的檔案不包含符合所需高度和寬度的影像,則會傳回具有最接近大小的圖示。

fileName如果它不在目前的應用程式目錄中,則應該包含完整路徑。

適用於