Click here to Skip to main content
16,010,470 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need easy way to write plugin Pin
leppie4-Jul-02 5:54
leppie4-Jul-02 5:54 
GeneralRe: Need easy way to write plugin Pin
leppie4-Jul-02 10:41
leppie4-Jul-02 10:41 
GeneralRe: Need easy way to write plugin Pin
James T. Johnson4-Jul-02 14:46
James T. Johnson4-Jul-02 14:46 
GeneralRe: Need easy way to write plugin Pin
leppie4-Jul-02 20:22
leppie4-Jul-02 20:22 
GeneralRe: Need easy way to write plugin Pin
leppie5-Jul-02 3:13
leppie5-Jul-02 3:13 
GeneralEUREKA I HAVE FOUND IT Pin
leppie5-Jul-02 4:45
leppie5-Jul-02 4:45 
QuestionResources... how??? Pin
3-Jul-02 7:43
suss3-Jul-02 7:43 
AnswerRe: Resources... how??? Pin
James T. Johnson3-Jul-02 10:28
James T. Johnson3-Jul-02 10:28 
If you have VS.NET (or Visual C# Standard or VB.NET Standard) embedding a bitmap resource is fairly easy.

1st: Add the bitmap to your project.
2nd: Set the "Build Action" of the bitmap to "Embedded Resource", this is set in the properties for the bitmap.
3rd: Figure out the name of the bitmap in the built assembly. To do this, take the default namespace of the project, then append any folders the bitmap may be in, finally append the bitmaps filename.

ex. The default namespace of your project is "defnamespace", the bitmap is placed inside a folder named "images" and the bitmap is named "mybitmap.bmp". The full name of the bitmap in the assembly is "defnamespace.images.mybitmap.bmp".

One of the Bitmap's constructors takes the namespace of a Type that is passed in, and appends the filename that is also passed in to find the bitmap to load from.

The constructor looks like this:
Bitmap(Type type, string filename)

To use it; supply the type that matches the full name of the bitmap; then for the filename supply what is missing.

ex. If the Type passed in has the namespace of "mycompany.myproduct" and the filename passed in is "images.mybitmap.bmp" it will search for a bitmap named "mycompany.myproduct.images.mybitmap.bmp".

If you prefer to get a Stream object (which works for any file) life gets easier for you Smile | :)

First you need a reference to the Assembly that contains the bitmap; unless you're dealing with multiple assemblies, you can get that by getting the Type that represents the class you are dealing with (GetType() for instance methods or typeof(MyClass) for static methods) then use the Assembly property on it.

Now call the GetManifestResourceStream and pass in the full name of the bitmap.

Use the stream it returns to load the bitmap up as if it were any other stream.

ex. The full name of the bitmap is "mycompany.myproduct.resources.mybitmap.bmp" and the class is named "MyClass".

System.IO.Stream stream = null;
Bitmap bitmap = null;
 
stream = typeof(MyClass).Assembly.GetManifestResourceStream("mycompany.myproduct.resources.mybitmap.bmp");
 
bitmap = new Bitmap(stream);
There is an overload of GetManifestResourceStream which takes the same parameters as the Bitmap constructor that was discussed. But if you wanted to use that form, you may as well use the Bitmap constructor.

HTH,

James
"Java is free - and worth every penny." - Christian Graus
GeneralMouseLeave Pin
SHaroz3-Jul-02 7:38
SHaroz3-Jul-02 7:38 
GeneralRe: MouseLeave Pin
NormDroid6-Jul-02 2:13
professionalNormDroid6-Jul-02 2:13 
GeneralListing Items Alphabetically in TreeView Pin
cAptHiDDeN3-Jul-02 4:48
cAptHiDDeN3-Jul-02 4:48 
GeneralTransparent User Controls Pin
2-Jul-02 11:21
suss2-Jul-02 11:21 
GeneralLocalization in ASP.NET Pin
2-Jul-02 5:08
suss2-Jul-02 5:08 
GeneralTEXTBOX Pin
vikramlinux2-Jul-02 3:32
vikramlinux2-Jul-02 3:32 
GeneralRe: TEXTBOX Pin
Chris Rickard2-Jul-02 4:11
Chris Rickard2-Jul-02 4:11 
GeneralRe: TEXTBOX Pin
vikramlinux2-Jul-02 5:48
vikramlinux2-Jul-02 5:48 
GeneralRe: TEXTBOX Pin
Sorin Comanescu3-Jul-02 22:42
Sorin Comanescu3-Jul-02 22:42 
GeneralJoining two DataTables to a CheckListBox control... Pin
Andrew Connell2-Jul-02 3:28
Andrew Connell2-Jul-02 3:28 
GeneralAll treenodes in a treeView Pin
2-Jul-02 1:20
suss2-Jul-02 1:20 
GeneralRe: All treenodes in a treeView Pin
James T. Johnson3-Jul-02 8:58
James T. Johnson3-Jul-02 8:58 
GeneralThe C# using operator Pin
Chris Maunder1-Jul-02 15:47
cofounderChris Maunder1-Jul-02 15:47 
GeneralRe: The C# using operator Pin
Andy Smith1-Jul-02 16:03
Andy Smith1-Jul-02 16:03 
GeneralRe: The C# using operator Pin
Rama Krishna Vavilala1-Jul-02 16:05
Rama Krishna Vavilala1-Jul-02 16:05 
GeneralRe: The C# using operator Pin
Chris Maunder1-Jul-02 16:25
cofounderChris Maunder1-Jul-02 16:25 
GeneralRe: The C# using operator Pin
Rama Krishna Vavilala1-Jul-02 16:03
Rama Krishna Vavilala1-Jul-02 16:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.