In a previous articleArticle: Wf4.0 workflow designer. A workflow designer is hosted in WPF. Its toolbar is as follows:
You will find that all the activities on the toolbar do not have icons, but in Visual Studio, the WF designer toolbar is shown as follows:
You will find the activity icons in Visual Studio very beautiful. These icons are not in the directory where Visual Studio is installed. Now I will find these icons from DLL.
First, lock the target: Microsoft. visualstudio. Activities. dll. Find it from your drive C, copy it to a directory, and put it under c. Use the followingCode:
1. loadtoolboxiconsforbuiltinactivities: loads the built-in activity icons.
Private Static Void Loadtoolboxiconsforbuiltinactivities ()
{
Attributetablebuilder Builder = New Attributetablebuilder ();
Assembly sourceassembly = Assembly. LoadFile ( @" C: \ microsoft. visualstudio. Activities. dll " );
System. Resources. resourcereader = New System. Resources. resourcereader (sourceassembly. getmanifestresourcestream ( " Microsoft. visualstudio. Activities. Resources. Resources " ));
If (type. namespace = "system. Activities. Statements ")
{
Createmedilboxbitmapattributeforactivity (builder, resourcereader, type ); }
Metadatastore. addattributetable (builder. createtable ());
}
2. createconlboxbitmapattributeforactivity
Private Static Void Createmedilboxbitmapattributeforactivity (attributetablebuilder builder, system. Resources. resourcereader, type builtinactivitytype)
{
System. Drawing. Bitmap bitmap = Extractbitmapresource (resourcereader, builtinactivitytype. isgenerictype ? Builtinactivitytype. Name. Split ( ' ` ' )[ 0 ]: Builtinactivitytype. Name );
If (Bitmap ! = Null )
{
Type tbatype = Typeof (System. Drawing. toolboxbitmapattribute );
Type imagetype = Typeof (System. Drawing. Image );
Constructorinfo Constructor = Tbatype. getconstructor (bindingflags. Instance | Bindingflags. nonpublic, Null , New Type [] {imagetype, imagetype }, Null );
System. Drawing. toolboxbitmapattribute TMD = Constructor. Invoke ( New Object [] {Bitmap, bitmap }) As System. Drawing. toolboxbitmapattribute;
Builder. addcustomattributes (builtinactivitytype, guid );
}
}
3. extractbitmapresource
Private Static System. Drawing. Bitmap extractbitmapresource (system. Resources. resourcereader, String Bitmapname)
{
System. Collections. idictionaryenumerator dictenum = Resourcereader. getenumerator ();
System. Drawing. Bitmap bitmap = Null ;
While (Dictenum. movenext ())
{
If (String. Equals (dictenum. Key, bitmapname ))
{
Bitmap = Dictenum. Value As System. Drawing. Bitmap;
System. Drawing. Color Pixel = Bitmap. getpixel (bitmap. Width - 1 , 0 );
Bitmap. maketransparent (pixel );
Break ;
}
}
Return Bitmap;
}
4. Add the following code to the workflow Host:
Loadtoolboxiconsforbuiltinactivities ();
When you re-run your designer, you will be surprised to find that:
Some activity icons are not displayed in Microsoft. visualstudio. Activities. dll.
Reference code:/files/zhuqil/cs.rar
PS: BenProgramRun in visual studio2010 RC