Problem with ToolboxBitmap

Discussion in 'ASP .Net Building Controls' started by Igor, Jul 21, 2003.

  1. Igor

    Igor Guest

    Hallo,

    I create a Control inherited from Web.UI.Control. I create a BMP Image and
    name it as exactly so as the Control.
    Set the "Build Action" property to "Embedded Resource" and add a Atribute to
    the Class definition fo my Control.

    as so
    System.Drawing.ToolboxBitmap(GetType(MyContorl)) in VB.NET

    System.Drawing.ToolboxBitmap(typeof(Pager)) in C#

    if I create the Controls as single Control in project, I see the bitmap in
    the toolbox, if I have any other controls in the project I see the default
    Image.

    has anybody a solution for this problem?

    thanks

    Igor
    --
    ATTENTION:The eMail Address "" is not real!
    Igor, Jul 21, 2003
    #1
    1. Advertising

  2. Igor

    Gabriel Guest

    How would I change the icon that appears on the toolbox for a custom
    control?

    You can do this in different ways explained below. In all the cases
    the bitmap or icon should follow these rules:

    The bitmap or icon dimension should be 16X16 with 16 colors.
    The left-bottom pixel-color will be assumed to be the transparent
    color.
    Technique 1: Use a bitmap (not an icon, in the embedded resource) file
    implicitly without specifying the ToolboxBitmapAttribute for the type:
    Say, you have a custom control MyControl in the namespace MyNamespace,
    create a bmp file MyControl.bmp following the above rules. Add this
    file to your project at the top-level and make it an embedded
    resource. The project's default namespace should be MyNamespace.

    If the control's namespace and the project's default namespace don't
    match then move the bitmap to appropriate subfolders so that they
    match. If this is not possible, typically when the namespaces are not
    related at all then you cannot use this technique, use instead one of
    the techniques below using the ToolboxBitmap attribute.

    Create the assembly and the next time you add it to the toolbox the
    custom image in MyControl.bmp should be available in the toolbox.

    This is the easiest technique to implement as it doesn't require you
    to use the ToolboxBitmapAttribute in your type defenition.

    Technique 2: Use ToolboxBitmap attribute.
    Example 1:

    Use a bitmap (not icon) in the embedded resource with the same name as
    the type.
    Default Assembly Namespace: "MyAssemblyNamespace"


    namespace MyAssemblyNamespace

    {

    [ToolboxBitmap(typeof(MyCustomType))]

    public class MyCustomType : Component

    {...}

    }


    In the above scenario the runtime will look for a embedded bmp file of
    name MyCustomType.bmp in the project's root directory. Note that the
    default namespace and the type's namespace match.

    Example 2:

    If you want your icons in sub-directories then change the attribute
    like this:

    [ToolboxAttribute(typeof(MyCustomType),
    "ToolboxIcons.MyCustomType.bmp")]


    or

    [ToolboxAttribute(typeof(MyCustomType),
    "ToolboxIcons.MyCustomType.ico")]


    where the bmp or ico file (yap, now, when you explicity specify the
    resource, you can use an ico file) is in a sub-directory called
    "ToolboxIcons".

    Example 3:

    Sometimes your type's namespace and the default assembly namespace may
    be unrelated, in which case you have to use a different type that has
    the same namespace as the default assembly namespace to scope the
    embedded image file.
    Default namespace: "MyAssemblyNamespace"


    namespace MyAssemblyNamespace

    {

    public class SomeType

    {...}

    }

    namespace DifferentNamespace

    {

    // Using SomeType which has the same namespace as the default
    assembly namespace to scope the embedded resource.

    [ToolboxBitmap(typeof(SomeType), "MyCustomType.ico")]

    public class MyCustomType

    {...}

    }


    In this case the runtime will look for the above resource at the
    top-most directory. If your icons were in a subdirectory named
    "ToolboxIcons" then the attribute would look like this:

    [ToolboxBitmap(typeof(SomeType),
    "ToolboxIcons.MyCustomType.ico")]


    Regards

    Gabriel

    "Igor" <> wrote in message news:<>...
    > Hallo,
    >
    > I create a Control inherited from Web.UI.Control. I create a BMP Image and
    > name it as exactly so as the Control.
    > Set the "Build Action" property to "Embedded Resource" and add a Atribute to
    > the Class definition fo my Control.
    >
    > as so
    > System.Drawing.ToolboxBitmap(GetType(MyContorl)) in VB.NET
    >
    > System.Drawing.ToolboxBitmap(typeof(Pager)) in C#
    >
    > if I create the Controls as single Control in project, I see the bitmap in
    > the toolbox, if I have any other controls in the project I see the default
    > Image.
    >
    > has anybody a solution for this problem?
    >
    > thanks
    >
    > Igor
    Gabriel, Aug 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    3,968
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,147
    Ted Miller
    Sep 13, 2003
  3. studen771

    Toolboxbitmap Attribute for custom control

    studen771, Apr 29, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    310
    studen771
    Apr 29, 2006
  4. Nathan Sokalski

    Using the System.Drawing.ToolboxBitmap Attribute

    Nathan Sokalski, Jan 9, 2009, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    1,217
    Nathan Sokalski
    Jan 9, 2009
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    544
    Bullschmidt
    May 11, 2004
Loading...

Share This Page