다음을 통해 공유


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

Visual Studio의 도구 상자에서 컨트롤에 대한 특수 아이콘을 표시하려는 경우 ToolboxBitmapAttribute를 사용하여 특정 이미지를 지정할 수 있습니다. 이 클래스는 특성이라는 다른 클래스에 연결할 수 있는 특수한 유형의 클래스입니다. 특성에 대한 자세한 내용은 Visual Basic의 경우 속성 개요(Visual Basic) 또는 C#인 경우 속성(C#)을 참조하세요.

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

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

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

    ' 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
    {
    }
    
  2. 프로젝트를 다시 빌드합니다.

    참고

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

참고 항목