您的位置:首页 > 编程语言 > C#

C#资源文件操作示例 - 创建资源和读取资源

2011-06-13 14:22 375 查看
1.新建一个Windows应用程序UseRes,用来调用资源。
新建一个类库Res用来存储资源文件。如图:



2.为Res项目添加资源文件Res.resx
并添加三个资源:
HongYe.ico
girl.gif
字符串strTest值Hello World
3.把Res.resx访问修饰符由Internal修改为Public
这样可以在其他项目中调用。
4.为UseRes添加Res项目引用。
5.读取资源的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UseRes
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}

private void btnRead_Click(object sender, EventArgs e)
{
//读取资源
Icon icon = Res.Res.HongYe;
Bitmap bitmap = Res.Res.girl;
string strTest = Res.Res.strTest;
//
this.Icon = icon;
this.pictureBox1.Image = bitmap;
MessageBox.Show(strTest);
}
}
}原文:http://www.it100.info/res.html
运行结果



本文源码:http://dotnet.5d6d.com/thread-318-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐