다음을 통해 공유


방법: 컨트롤에 대한 도구 상자 비트맵 제공

업데이트: 2007년 11월

도구 상자에 표시되는 컨트롤에 특수 아이콘을 사용하려면 ToolboxBitmapAttribute를 사용하여 특정 이미지를 지정합니다. 이 클래스는 다른 클래스에 연결할 수 있는 특수 클래스인 특성입니다. 특성에 대한 자세한 내용은 Visual Basic의 특성 개요(Visual Basic) 및 특성(C# 프로그래밍 가이드)(Visual C#)를 참조하십시오.

ToolboxBitmapAttribute를 사용하여 16x16 픽셀 비트맵의 경로 및 파일 이름을 나타내는 문자열을 지정할 수 있습니다. 그러면 컨트롤을 도구 상자에 추가할 때 컨트롤 옆에 이 비트맵이 나타납니다. 특정 형식과 연결된 비트맵이 로드되도록 Type을 지정할 수도 있습니다. Type과 문자열을 모두 지정하면 컨트롤에서는 Type 매개 변수로 지정된 형식이 포함된 어셈블리에서 문자열 매개 변수로 지정된 이름을 가진 이미지 리소스를 검색합니다.

컨트롤을 위한 도구 상자 비트맵을 지정하려면

  1. ToolboxBitmapAttribute를 컨트롤의 클래스 선언에 추가합니다. Visual Basic에서는 Class 키워드 앞에 추가하고 Visual C#에서는 클래스 선언 위쪽에 추가합니다.

    ' Specifies the bitmap associated with the Button type.
    <ToolboxBitmap(GetType(Button))> Class MyControl1
    ' Specifies a bitmap file.
    End Class
    <ToolboxBitmap("C:\Documents and Settings\Joe\MyPics\myImage.bmp")> _
       Class MyControl2
    End Class
    ' Specifies a type that indicates the assembly to search, and the name 
    ' of an image resource to look for.
    <ToolboxBitmap(GetType(MyControl), "MyControlBitmap")> Class MyControl
    End Class
    
    // Specifies the bitmap associated with the Button type.
    [ToolboxBitmap(typeof(Button))]
    class MyControl1 : UserControl
    {
    }
    // Specifies a bitmap file.
    [ToolboxBitmap(@"C:\Documents and Settings\Joe\MyPics\myImage.bmp")]
    class MyControl2 : UserControl
    {
    }
    // Specifies a type that indicates the assembly to search, and the name 
    // of an image resource to look for.
    [ToolboxBitmap(typeof(MyControl), "MyControlBitmap")]
    class MyControl : UserControl
    {
    }
    
    // Specifies the bitmap associated with the Button type.
    /** @attribute ToolboxBitmap(Button.class)  */
    class MyControl1 extends UserControl
    {
    }
    // Specifies a bitmap file.
    /** @attribute ToolboxBitmap("C:\\Documents and Settings\\Joe\\MyPics\\myImage.bmp")*/
    class MyControl2 extends UserControl
    {
    }
    // Specifies a type that indicates the assembly to search, and the name 
    // of an image resource to look for.
    /* @attribute ToolboxBitmap(MyControl.class, "MyControlBitmap") */
    class MyControl extends UserControl
    {
    }
    
  2. 프로젝트를 다시 빌드합니다.

    참고:

    비트맵은 자동 생성된 컨트롤 및 구성 요소의 도구 상자에는 나타나지 않습니다. 비트맵을 보려면 도구 상자 항목 선택 대화 상자를 사용하여 컨트롤을 다시 로드합니다. 자세한 내용은 연습: 도구 상자에 자동으로 사용자 지정 구성 요소 채우기를 참조하십시오.

참고 항목

작업

연습: 도구 상자에 자동으로 사용자 지정 구성 요소 채우기

참조

특성(C# 프로그래밍 가이드)

ToolboxBitmapAttribute

기타 리소스

디자인할 때 Windows Forms 컨트롤 개발

Visual Basic 특성