DOTNET Compact Framework Middle-Amail Resource Usage Learning Notes

xiaoxiao2021-03-05  18

problem:

When writing an application running under Wince, use Visual Studio.net 2003, you need to use bitmap resources, so use the following code:

Using system.drawing;

... ..

Bitmap Picbitmap = New Bitmap ("Pica.bmp");

......

Pica.BMP is the bitmap file I want to use, I attached this file to the project directory, compile, start debug, but find that Pica.bmp has been copied in Wince Emulator while deploying this application. In the same directory, but the program is running to this location, I will throw a "filenotfoundexception", and the same code is running in the Windows application.

analysis:

Due to insufficient experience in all aspects, I didn't want to know it now.

solve:

1. Observe how VS.NET uses bitmap resources.

New WINDOWS FORM app, create a new form: Form1, drag into a Picturebox: PBSHOW on the form, set the image of the PBSHOW to your own bitmap. Then look at the source code of Form, find the problem:

System.Resources.ResourceManager Resources = New System.Resources.ResourceManager (TypeForm);

This.PictureBox1.image = ((System.drawing.Image) ("PictureBox1.image)))));

It turns out that VS.NET is used by the .NET resource file to use a median resource.

Suppose our project name is called SmartDeviceApplication1, named SMARTAPP, then in the directory SmartDeviceApplication1 / Obj / Debug directory you can find a .NET resource file called Smartapp.form1.Resources. This file is automatically generated by .Net, but because we want to use your own resources, we have to learn to edit and use this file.

2, edit * .resources file

The VS.NET comes with a resource editor called Reseditor, usually in / program files / microsoft Visual Studio .NET 2003 / SDK / V1.1 / Samples / Tutorials / Resources (maybe due to Visual Studio) The version of the .NET version is different.), This directory will contain two files of build.bat and reSeditor.cs, reSeditor.cs is the source code of the resource editor, Microsoft does not provide compiled programs, how to say It is an open source. Open Start Menu | Program | Microsoft Visual Studio .NET 2003 | Visual Studio .NET Tools | Visual Studio .NET 2003 Command Tips, positioning to the directory, running Build.bat, you can compile this file. Running ReSeditor, you can compile the resources we want. The interface is as shown:

Such an interface is also very simple, and it is also very simple: select the resource type you want to add in the Add drop-down box, we choose: system.drawing.bitmap, take a name to him in the next textbox, For example, called Fortest, click the Add button on the right, click the ... button to browse to the picture you want to add. Save the file from the file as .resources.

3, use resource files

Additional compiled files to your project, right-click Engineen name, add | Add existing items, select resource files, such as called Myres.Resources, we need resourceManager in the program to use bitmaps in the file. ResourceManager can also be used to solve the internationalization of software, and we will not introduce here.

System.Resources.ResourceManager RM = New ResourceMagager ("Smartapp.myres", System.Reflection.Assembly.GetexecutingAssembly ());

Bitmap Picbitmap = (Bitmap) RM.GetObject ("Fortest");

If you add String in the resource file, we can use GetString directly without the need to use forced type conversion.

SMARTAPP here is the namespace of our program, Myres is a file name, remember not to bring a suffix. This will use our bitmap resources correctly! ^ _ ^

转载请注明原文地址:https://www.9cbs.com/read-38568.html

New Post(0)