set icon for a windows control

hamid

Centurion
Joined
Jul 13, 2004
Messages
114
i create a windows control and it is an advanced TextBox, now i want set a textbox icon for it that when i add it to my toolbox it shown as like as microsoft TextBox :rolleyes:
 
You need to use the System.Drawing.ToolBoxBitmapAttribute class.
Visual Basic:
Imports System.Drawing

<ToolboxBitmap(GetType(MyTextBox), "NameOfResource")> _
Public Class MyTextBox
    '...
End Class
C#:
using System.Drawing;

[ToolboxBitmap(typeof(MyTextBox), "NameOfResource")]
public class MyTextBox {
    // ...
}
There are different overloads, but this is probably the best. You pass the name of the resource and an object type in your assembly so the constructor can find the assembly to extract the resouce.

The name of the resource isn't going to be the same as the name of the file. Depending on how it is added to the project, the name varies. It might be a good idea to compile the program, then decompile it with Reflector to find the name of the resource, then add the attribute.
 
Back
Top