Search for icons in Visual Studio in DLL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.