Home/ASP.NET Forums/Advanced ASP.NET/Custom Server Controls/Icon for custom server control

Icon for custom server control RSS

24 replies

Last post Apr 13, 2006 05:26 AM by dbottjer

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Laurent Duveau
MVP / MCT / RD
http://weblogs.asp.net/lduveau/
  • AnneB

    AnneB

    Member

    36 Points

    20 Posts

    Re: Icon for custom server control

    Dec 12, 2005 04:53 PM|AnneB|LINK

    Laurent,

    If you refer back to my original posting, you'll see that I gave the bitmap the same name as the control, and I set the Build Action property to Embedded Resource. I'm also sure that the bitmap is 16 x 16, and it uses only three colors. Are there only certain colors it can use? By the way, I used this bitmap with the same user control I created in Visual Studio 2003, so it seems that it should work in 2005. Have you actually tried the technique you're describing to me? Seems like it should work, but it doesn't!

    Anne

  • Pluginbaby

    Pluginbaby

    Contributor

    2961 Points

    486 Posts

    MVP

    Re: Icon for custom server control

    Dec 12, 2005 07:02 PM|Pluginbaby|LINK

    Yes, I'm curently creating a custom control so I tried these technique for myself, and it works (VS 2005 final)

    I don't know what's wrong with yours ?

    Did you try to remove the control from the toolbox and put it again from your fresh-built assembly ?

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    MVP / MCT / RD
    http://weblogs.asp.net/lduveau/
  • Luis Abreu

    Luis Abreu

    All-Star

    25674 Points

    5369 Posts

    MVP

    Re: Icon for custom server control

    Dec 14, 2005 11:28 AM|Luis Abreu|LINK

    hello guys.

    have you checked the namespace of the resource? since you're building a server control, you should be building a dll, right? if that is true, then check the namespace of the project (look at the projects property). that namespace will be included in the resource name. for instance, if the namespace is X and your resource is called T.bmp, then the resource wil be identified as X.T.bmp. so, if you want to use the attribute i've mentioned, you should put X.T.bmp instead od T.bmp. btw, if you want to be sure about the name of the resource, you can use .Net Reflector to see its name on the assembly.

    --
    Regards,
    Luis Abreu
    email: labreu_at_gmail.com
    EN blog:http://msmvps.com/blogs/luisabreu
  • MANNY100

    MANNY100

    Member

    10 Points

    2 Posts

    Re: Icon for custom server control

    Feb 23, 2006 10:44 AM|MANNY100|LINK

    Hi

    I was having same issue. What you need to do is import the follwing

    Imports System.Drawing

    Then you can add

    ToolboxBitmapAttribute(gettype(namspace.class),"Youbitmap.bmp"))

  • dbottjer

    dbottjer

    Contributor

    2410 Points

    466 Posts

    Re: Icon for custom server control

    Feb 24, 2006 02:04 AM|dbottjer|LINK

    This seems a little tricky to get working but I would recommed the technique posted by Manny

    Imports System.Drawing

    Then you can add

    ToolboxBitmapAttribute(gettype(namspace.class),"Youbitmap.bmp"))

    It has been my experience that you either need to embed the bitmap within your control assembly and specify your assembly name as shown above.  You can also do something like: ToolboxBitmapAttribute("c:\inetpub\wwwroot\mycustomcontrol\mycustomcontrol.bmp") Although I don't really like this method.

    Thanks,

    Dennis J. Bottjer
    ThriveFast | Blog | Follow Me @dbottjer
    Please "Mark As Answer" if helped
  • jstuardo

    jstuardo

    Member

    237 Points

    81 Posts

    Re: Icon for custom server control

    Feb 25, 2006 07:47 PM|jstuardo|LINK

    I am having the same problem with my Composite Control.

    I placed:

    [ToolboxBitmap(typeof(StuartWebControl.DateSelector), "DateSelector.bmp")]

    but it didn't work either. The gear is still appearing. I have VS 2005.

    Jaime

  • Pluginbaby

    Pluginbaby

    Contributor

    2961 Points

    486 Posts

    MVP

    Re: Icon for custom server control

    Feb 26, 2006 03:43 PM|Pluginbaby|LINK

    Hi,

    Did you make the bmp an embedded resource of your assembly ?
    To enable the bitmap as an embedded resource, right-click the bitmap file and select the Properties menu item. From the Properties page, set the Build Action to Embedded Resource.

    Did you place it in a sub-folder or in the root of the project ?

    Maybe could you try this :
    [ToolboxBitmap(typeof(StuartWebControl.DateSelector), "StuartWebControl.DateSelector.bmp")]

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    MVP / MCT / RD
    http://weblogs.asp.net/lduveau/
  • leabre

    leabre

    Member

    700 Points

    140 Posts

    Re: Icon for custom server control

    Mar 17, 2006 08:37 PM|leabre|LINK

    I'm also having this problem.  I created about 200 server controls a few years back in VS.NET 2003 and the icons work perfectly.  They are not 16 color, they are 256 color.  Either way, VS.Previous has not problems displaying it perfectly.  However, in 2005, I cannot do anything to get the icon (BMP) in the toolbox, even doing all the things described in this email.  However, I will try to fully quality the namespace.  I only qualified the part after the default namespace in VS.Previous and that was good enough, let you know how it turns out.

     

    Thanks,
    Shawn

  • VBAHole22

    VBAHole22

    Member

    351 Points

    73 Posts

    Re: Icon for custom server control

    Apr 05, 2006 03:27 AM|VBAHole22|LINK

    Have you tried to add an assembly reference to the image  above your class after changing the property to embedded?

    [assembly: WebResource("MyAssembly.MyControl.images.BarrowRight.gif", "image/gif")]

    Then reference the image as

    btnUp.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyAssembly.MyControl.images.BarrowUp.gif");

     

    Worth a shot i suppose

  • VBAHole22

    VBAHole22

    Member

    351 Points

    73 Posts

    Re: Icon for custom server control

    Apr 11, 2006 02:40 PM|VBAHole22|LINK

    I too have tried every suggestion in this thread with no luck. I think I like the gear more and more each day as I waste time trying to get my own image in.
  • Pluginbaby

    Pluginbaby

    Contributor

    2961 Points

    486 Posts

    MVP

    Re: Icon for custom server control

    Apr 11, 2006 04:25 PM|Pluginbaby|LINK

    :-)

    Maybe could you post here the code you use ?

    VS2005 or VS2003 ?

    C# or VB ?

    what king of image do you use ?

     

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    MVP / MCT / RD
    http://weblogs.asp.net/lduveau/
  • VBAHole22

    VBAHole22

    Member

    351 Points

    73 Posts

    Re: Icon for custom server control

    Apr 12, 2006 07:14 PM|VBAHole22|LINK

    VS2005 aspnet 2.0 C#

    16x16 BMP 16 colors

    on my custom control class I have

    System.Drawing.ToolboxBitmap(typeof(MyControl), "MyControl.bmp")

    I have tried to put the image in the root, put it in an image folder, alter the above to include the namespace, embed the image and use it as an assembly resource, and about 10 other things.

    I'm confused as to why it won't work

  • leabre

    leabre

    Member

    700 Points

    140 Posts

    Re: Icon for custom server control

    Apr 12, 2006 09:21 PM|leabre|LINK

    Does it have to be 16 colors?  256 color worked just fine in 2003, I know, I have over 200 custom server controls I've written over the years and 256 color 16x16 bitmap has worked fine.  I cannot for the life of me make it work in VS 2005.  I gave up trying.  Even when I create a blank project with a blank do-nothing server control with a 16x16 bitmap embadded as a resource and the code listed above (or code that worked perfectly fine when I create the same scratch project in 2003 -- and in 2003 it works) and still, no icon in 2005.

     

    Thanks,
    Shawn

  • VBAHole22

    VBAHole22

    Member

    351 Points

    73 Posts

    Re: Icon for custom server control

    Apr 13, 2006 04:52 AM|VBAHole22|LINK

    I have finally gotten this to work after trying just about every conceivable way. What finally got it working for me was this.

    16x16x16colors bmp

    had to put it in the root folder alongside the control and named the same as the control (not the full qualified name though - in this case just MycontrolName.bmp)

    the tag I used on the control class was of the following format

    System.Drawing.ToolboxBitmap(typeof(MyFullAssemblyName.MycontrolName))

    not the method with 2 params as i have seen elsewhere

    i had to remove it from the toolbox and add it back to see the effect

    I did not need an assembly reference anywhere

    You can tell if it is going to work because you should see the icon when you are adding the toolbox item in the choose item dialog box.

    the only issue I have now is that I have this lone image file hanging out in my root folder but hey its the price you pay i guess. I think that is all the pertinent details. Hope this helps someone else and good luck if you are stuck on this one.

  • dbottjer

    dbottjer

    Contributor

    2410 Points

    466 Posts

    Re: Icon for custom server control

    Apr 13, 2006 05:26 AM|dbottjer|LINK

    The two params method works as well.  I posted an example on 2/23/2006.  It seems that placing the bitmap in the root folder is key along with the dimensions of the bitmap as you suggested 16x16x16colors.

    Thanks,

    Dennis J. Bottjer
    ThriveFast | Blog | Follow Me @dbottjer
    Please "Mark As Answer" if helped
  • ‹ Previous Thread|Next Thread ›