Prerequisites: You must set the <generate operation> attribute to [embedded resource] In the properties page of each of the following types of resources to be introduced:
:
►Solutions for adding custom icons to custom controls
Method 1:
Add an icon file in *. BMP format in the custom control project and name it
Same as the main control file, the extension is. bmp. For example, the main control file name is:
Custombutton. CS, the icon file is named custombutton.bmp. compile the project.
Then add this control in the toolbox to see the icon effect you just set.
Method 2:
The name of the icon file is different from the name of the main control. Set the name as follows before the class.
[Toolboxbitmap (typeof (custombutton), @ "custombutton1.bmp")]
Public class custombutton: compositecontrol, inamingcontainer
{
//....;
}
Compile the project, and add this control in the toolbox to see the icon effect you just set.
Method 3:
The icon file name is different from the Master Control name, and the local absolute path is used as follows:
[Toolboxbitmap (@ "E: \ net \ custombutton (test Resource
File) \ custombutton \ custombutton1.bmp ")]
Compile the project, and add this control in the toolbox to see the icon effect you just set.
►Custom controls embed Javascript file resources
1. define metadata attributes
[Assembly: webresource ("custombutton. custombutton_jscript.js ",
"Application/JavaScript")]
Namespace custombutton
{
//....;
}
Here, parameter 1 of webresource is: Control namespace +. + JS script file name
2. Use
If (! Page. clientscript. isclientscriptincluderegistered
("Myjavascript "))
{
Page. clientscript. registerclientscriptinclude
("Myjavascript", page. clientscript. getwebresourceurl
(This. GetType (), "custombutton. custombutton _ JScript. js "));
}
►Custom control embedded image (GIF/jpg) file resources
1. define metadata attributes
[Assembly: webresource ("custombutton.nopic.gif", "image/GIF")]
Namespace custombutton
{
//....;
}
2. Use
string strimagesrc = page. clientscript. getwebresourceurl
(this. getType (), "custombutton.nopic.gif");
system. web. UI. webcontrols. image IMG = new
system. web. UI. webcontrols. image ();
IMG. imageurl = strimagesrc;