Reputation: 18746
I followed the trail of the ToolstripMenu in designer to the following line:
(System.Drawing.Bitmap) new System.ComponentModel.ComponentResourceManager(typeof(FormMain)).GetObject("saveToolStripButton.Image")
I can duplicate that and use it my form code as long as the toolstripMenuItem is on the form. Is it possible to access these icons directly instead of having to add a Toolstrip and its standard items?
Upvotes: 0
Views: 3444
Reputation: 5667
Visual Studio generally uses resource files to manage icons, display texts, and many other resources. And those files (identified by the .resx extension) are XML, so you can view them even in the VS IDE itself.
In the case of ToolStrip auto-generated buttons, the icons are saved inline within the form's resource file, using base64 enconding. To find the resource file, expand the node corresponding to your form in the Solution Explorer, the .resx should be there together with the .Designer.cs file. Here the fun begins: there are lots of things you can do with those resources:
Option 1: Double-click the .resx file on the Solution Explorer to open it with the IDE's built-in resource editor. At the top-left corner of that window, you will see a dropdown button from which you can choose "Images". There you have the icons in their fullest glory. By right-clicking on them, you can do many things, including exporting them to a file.
Option 2: If you right-click the .resx file and select Open with
| XML (Text) Editor
, you will see the raw XML code of the file. You can add a resource file to your project and open it in the code editor the same way, and then you can look for the chunks defining the icons (when you encounter a block of gibberish text, look the tags around it to know what is it) and copy-paste them from one .resx file to the other. Give them simpler names, and then you should be able to reference your own .resx to pick images for your menus, controls, etc.
Option 3: You could copy the base64-encoded data and decode it with some base64 utility, but the result will be quite the same as exporting the images to files as described in Option 1.
Do not try to hack the designer-generated .resx file itself. In theory, if you knew what you were doing, you could get other controls in the form wired to the same resources... but if you are reading this, you don't know enough about the VS Designer's internals to get this right, so save yourself the headache ;).
Upvotes: 0
Reputation: 21
Dim ListViewType As System.Type = GetType(System.Windows.Forms.ListView)
Dim ImageFetcher As New System.Drawing.ToolboxBitmapAttribute(ListViewType)
Dim large As Boolean = False
Dim ListViewTBitmap As New System.Drawing.Bitmap(ImageFetcher.GetImage(chkBoxType, large))
Upvotes: 2
Reputation: 8381
Assuming you're using visual studio, the icons are available for your use in the following location C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary
If VS 2005 change 9.0 to 8
Upvotes: 3