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

c#窗口中的资源读取 Form.resx

2011-07-05 08:24 423 查看
来自:http://www.badteen.net/?post=338

新建的项目文件中,一般有两种资源形势的文件,“*.resx”和“Resources.resx” 在这里只讲述“*.resx”文件的利用:

/// <summary>
/// 从资源中加载图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//资源管理"typeof(Form1)"指定为Form1.resx,可以改成其他的
ResourceManager rm = new ResourceManager(typeof(Form1));
//类型转换
//"Image1"是资源名称
Bitmap bitMap = (Bitmap)rm.GetObject("Image1");
//显示
this.pictureBox1.Image = bitMap;
}
/// <summary>
/// 从资源中显示字符串
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
ResourceManager rm = new ResourceManager(typeof(Form1));
//显示字符串
//"String1"是资源名称
this.textBox1.Text = rm.GetString("String1");
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: