HowTo: creating bitmap resources for custom controls

B

Bjoern Feld

Hi,

I am fairly new to the .NET CF. I just managed to create my own custon=m
controls with designer support.
I ran into a problem embedding a bitmap resource:
I wanto to display a small bmp as logo. I added the bitmap to my solution
and set the build action to "embedded resource". I tried loading the image
in my constructor using GetManifestRes... The code compiles fine. but trying
to place the control on a form in designer returns an Exception (stream
cannot be null). Putting the bmp file name in "" bitmap constructor work for
the designer, but not when I deploy my test app and the control.
How do I embed a resource I tried looking up the .resx files. But I cannot
find a way to get my bitmap into it. Using the ResGen.exe seems to create
only .Resx files for the full .Net framework and seems to be not compatible
with CF framework.

TIA,
Bjoern
 
A

Alex Yakhnin, MVP

Did you include your bitmap as an embedded resource into your design-time
version?
How do you compile it?
 
B

Bjoern Feld

Alex,

I use the ide to build my code and the use the comandline compiler approach
using rsp files which is described in the core reference book.(Mircosoft
..Net Compact Framework).
I think I know where my pronblem lies: I didn't include the bmp file in my
rsp file.

This is my designer.rsp file

/define:NETCFDESIGNTIME
/out:TargetControlsDesigner.dll
/target:library
TDoseRateDisplay.cs
THeaderBar.cs
TCountrateFinder.cs
/r:"C:\Programme\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows CE\Designer\System.CF.Design.dll"
/r:"C:\Programme\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Windows.Forms.dll"
/r:"C:\Programme\Microsoft Visual Studio .NET
2003\CompactFrameworkSDK\v1.0.5000\Windows
CE\Designer\System.CF.Drawing.dll"
/r:System.Windows.Forms.dll
/r:System.Drawing.dll
/r:System.dll
/nowarn:1595
 
E

Ed Kaim [MSFT]

Okay, but it sounds like you're trying to use the same DLL for design-time
and runtime, which isn't supported. The whitepaper I pointed to explains how
to make a design-time version of the assembly since runtime versions of .NET
CF controls can't be used in the VS designer.
 
B

Bjoern Feld

I do have my design time assembly and the runtime assembly.
The problem is if I put my bmp file as an embedded resource into my
solution. I compile run and design time version, copy them to the cf
directories and I am able to place my control on my form, if I use
Bitmap myBMP = new Bitmap("logo.bmp"); in my controls constructor.
However if I deploy to the emulator I get an exception at that point.

I tried using creating the bitmap using GetManifestResourceStream:
Bitmap myBMP = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("controlnam
e.logo.bmp")

This gives me a Stream exception in both design and runtime dll.

Do I miss something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top