.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).
Re: .NET Component Resources?
Have a look at
System.Drawing.Icon
System.Drawing.Bitmap
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
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...
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