Using the System.Drawing.ToolboxBitmap attribute in VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Using the System.Drawing.ToolboxBitmap attribute in VB.NET

    I am attempting to create icons for controls I have created using VB.NET by
    using the System.Drawing. ToolboxBitmap attribute. I have managed to do this
    in C# by specifying the path to the *.ico file, but I have been unable to
    get any of the overloads to work in VB.NET. I would like to store the *.ico
    files in a *.resx file so that users do not need anything other than the
    *.dll, but at the moment I am just trying to get any of the overloads of
    System.Drawing. ToolboxBitmap to work in VB.NET. Here is my code and
    directories (obviously not all files are listed, but I think these are the
    ones of significance):

    NateCtrl2005 (this is the name of my project)
    My Project
    Resources.resx (this is the resources file with my *.ico files)
    ToolboxIcons (folder where I am storing the *.ico files)
    ConditionalRequ iredTextValidat or.ico (Build Action=Embedded
    Resource)
    ConditionalRequ iredTextValidat or.vb


    Code in ConditionalRequ iredTextValidat or.vb:

    Namespace NathanSokalski
    <System.Drawing .ToolboxBitmap( "C:\Inetpub\www root\NateCtrl20 05\ToolboxIcons \ConditionalReq uiredTextValida tor.ico")>
    Public Class ConditionalRequ iredTextValidat or
  • Nathan Sokalski

    #2
    Re: Using the System.Drawing. ToolboxBitmap attribute in VB.NET

    I have tried that, but I can't get that to work either.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


    "Fred" <foleide@free.f r.invalidwrote in message
    news:%23%23U5cv XPJHA.3560@TK2M SFTNGP02.phx.gb l...
    in news:%23DrHJfTP JHA.4772@TK2MSF TNGP03.phx.gbl, Nathan Sokalski wrote :
    >
    >I am attempting to create icons for controls I have created using
    >VB.NET by using the System.Drawing. ToolboxBitmap attribute.
    >
    In VB.NET, I just add a bmp file to the project and select «Embedded
    Resource» in the «Build Action» property.
    >
    Then I use the third new (Type, String) of the TooboxBitmapAtt ribute.
    >
    --
    Fred
    foleide@free.fr

    Comment

    • Kevin S Gallagher

      #3
      Re: Using the System.Drawing. ToolboxBitmap attribute in VB.NET

      MSDN http://msdn.microsoft.com/en-us/libr...0a(VS.80).aspx

      The following I picked up on the web but do not remember where

      Setting Toolbox Bitmaps
      By default, icons that you make display a little gear in the control
      toolbox. It's a cute icon, but it would- n't be very informative if you have
      dozens of controls that all display the same icon, particularly if you don't
      use the toolbox's list view so the icons and tooltips are the only tools you
      have for finding the controls you want.
      Unfortunately, setting a control's toolbox bitmap is rather tricky. To set
      the bitmap, you add a Toolbox Bitmap attribute to the control's class. This
      attribute has a couple of different constructors. The simplest gives the
      complete path to the control's 16_16-pixel bitmap file. The following code
      shows this type of attribute for the StyledListBox control:
      <ToolboxBitmap( "C:\StyledListB ox\Resources\tb xStyledListBox. bmp")_
      Public Class StyledListBox
      ...
      This version of the ToolboxBitmap attribute is simple and reliable.
      Unfortunately, it ties the code to a specific location. If you later move
      the toolbox bitmap, the statement no longer works.
      To avoid this problem, you can just leave the control and its files in the
      location where you initially build them. Another solution is to place all of
      your toolbox bitmaps in a directory somewhere and never move them. These
      solutions work, but restrict what you can do with the control's project. For
      example, if you email the project to someone else, they must modify the
      attribute's constructor so it can find the bitmap on the new computer.
      Another constructor provided by the ToolboxBitmap attribute takes as
      parameters the type of a class contained in an assembly, and then the name
      of a bitmap resource in that assembly. The following code shows this version
      of the attribute for the StyledListBox control:
      <ToolboxBitmap( GetType(StyledL istBox), "tbxStyledListB ox")_
      Public Class StyledListBox
      ...
      This code tells Visual Basic to look in the assembly containing the
      StyledListBox class for the resource named tbxStyledListBo x.
      In theory, this is a nice solution that lets the attribute find the bitmap
      resource even if you move the project. In practice, getting this to work can
      be tricky.
      First, add a 16_16-pixel bitmap resource to the project and draw the image
      you want to display in the toolbox. Next, select the bitmap file in the
      Solution Explorer. In the Properties window, set the bitmap's Build Action
      property to Embedded Resource.
      If all goes well, the control will get the correct toolbox bitmap.
      Unfortunately, if there's any kind of problem (for example, if Visual Basic
      cannot find the file or the class), you won't see an error message and the
      control gets the default gear icon.
      If you change the control's icon and still see the wrong icon in the
      toolbox, click the control in the tool- box, press the Delete key, and
      confirm that you want to remove the control from the toolbox. Next, right-
      click the toolbox and select Choose Items. Click the Browse button and find
      the compiled control's DLL or EXE file. When you select the file and click
      Open, the dialog adds the controls contained in that file to its list and
      selects them. Click the control's entry to preview its toolbox bitmap. If
      you see the gear bitmap (which you may be getting sick of by this point),
      click Cancel so you don't add the control to the toolbox (so you don't have
      to remove it again) and try again.



      "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
      news:%23DrHJfTP JHA.4772@TK2MSF TNGP03.phx.gbl. ..
      >I am attempting to create icons for controls I have created using VB.NET by
      >using the System.Drawing. ToolboxBitmap attribute. I have managed to do this
      >in C# by specifying the path to the *.ico file, but I have been unable to
      >get any of the overloads to work in VB.NET. I would like to store the *.ico
      >files in a *.resx file so that users do not need anything other than the
      >*.dll, but at the moment I am just trying to get any of the overloads of
      >System.Drawing .ToolboxBitmap to work in VB.NET. Here is my code and
      >directories (obviously not all files are listed, but I think these are the
      >ones of significance):
      >
      NateCtrl2005 (this is the name of my project)
      My Project
      Resources.resx (this is the resources file with my *.ico files)
      ToolboxIcons (folder where I am storing the *.ico files)
      ConditionalRequ iredTextValidat or.ico (Build Action=Embedded
      Resource)
      ConditionalRequ iredTextValidat or.vb
      >
      >
      Code in ConditionalRequ iredTextValidat or.vb:
      >
      Namespace NathanSokalski
      >
      <System.Drawing .ToolboxBitmap( "C:\Inetpub\www root\NateCtrl20 05\ToolboxIcons \ConditionalReq uiredTextValida tor.ico")>
      Public Class ConditionalRequ iredTextValidat or
      .
      End Class
      End Namespace
      >
      >
      I have tried all three overloads of System.Drawing. ToolboxBitmap, and
      could not get any of them to work. I have heard stuff about them not all
      working correctly in VB.NET, but even in C# I was only able to get the one
      where the path of the *.ico is specified to work. I think that Visual
      Studio should have some kind of attribute editor or something (it lets you
      use the Property Grid to set the Category and Default Value for
      properties, and several things for the class, but not this one or many of
      the others). If someone could help me I would appreciate it. Thanks.
      --
      Nathan Sokalski
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

      >

      Comment

      Working...