Results 1 to 5 of 5

Thread: .NET Component Resources?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    80

    .NET Component Resources?

    How could I get the icons for components in the toolbox into .ico or .bmp or whatever image format they are in, I've looked through system32 etc etc and searched online for hours but I just can't figure out how to get specific control's icons (like a textbox's).

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: .NET Component Resources?

    Have a look at
    System.Drawing.Icon
    System.Drawing.Bitmap
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .NET Component Resources?

    1) Not sure why you're after the icons... and 2) not sure why you're looking in the system32 folder since the icons are in the controls themselves.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: .NET Component Resources?

    The attribute is ToolBoxBitmap, and you can use reflection to get the icon. I'm looking now on MSDN for the method names...
    Last edited by minitech; May 15th, 2010 at 04:22 PM.

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: .NET Component Resources?

    Code:
    Dim t As Type = GetType(TextBox)
    Dim d As IList(Of CustomAttributeData) = CustomAttributeData.GetCustomAttributes(t)
    For Each attr As CustomAttributeData In d
         If attr.ToString().IndexOf("ToolboxBitmap") > -1 Then
              Dim bmp As Bitmap = Bitmap.FromFile(attr.NamedArguments(0).ToString().Split("="c)(1))
              Me.PictureBox1.Image = bmp
              Exit For
         End If
    Next
    This doesn't work for embedded resources, though... I'm not sure if the TextBox works that way. However, you can get the assembly name and the resource name:
    Code:
    Dim t As Type = GetType(TextBox)
    Dim d As IList(Of CustomAttributeData) = CustomAttributeData.GetCustomAttributes(t)
    For Each attr As CustomAttributeData In d
         If attr.ToString().IndexOf("ToolboxBitmap") > -1 Then
              Dim assemblyName As String = attr.NamedArguments(0).ToString().Split("="c)(1)
              Dim resourceFile As String = ""
              If attr.NamedArguments.Count > 1 Then resourceFile = attr.NamedArguments(1).ToString().Split("="c)(1)
              MessageBox.Show("The bitmap is in the assembly """ & assemblyName & """ and the resource name of the bitmap is """ & resourceFile & """.")
              Exit For
         End If
    Next
    Last edited by minitech; May 15th, 2010 at 04:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width