您的位置:首页 > 其它

今天遇到的一些问题

2007-01-19 14:35 288 查看
当我们在应用程序中的资源文件里插入一个图片后,想在某一个窗体上以这个图片为背景,那么就需要读取资源文件,在C#中,似科每一个窗体都有一个自己独立的资源文件,这样的话,读取一个资源时会涉及命名空间的问题,我现在还不清楚这个命名空间是如何区别的。

MSDN 上用如下的代码读取资源文件中的图片,但在程序中出错,这里的关键是不是就是命名空间的问题?

那么它这段代码就应该是读取窗体中的资源,而不是工程中的资源

using System.IO;

public Form1() {
...

// Get this type's assembly
Assembly assem = this.GetType().Assembly;

// Get the stream that holds the resource
// NOTE1: Make sure not to close this stream!
// NOTE2: Also be very careful to match the case
//        on the resource name itself
Stream stream =
assem.GetManifestResourceStream("Azul.jpg");

// Load the bitmap from the stream
this.BackgroundImage = new Bitmap(stream);
}

那么如果要读取工程中的资源,要用怎么样的命名空间呢?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: