📄 mainwnd.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Resources;
using System.Reflection;
namespace ResourceConsumer
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class MainWnd : System.Windows.Forms.Form
{
private System.Windows.Forms.Button LoadImg;
private System.Windows.Forms.Button LoadString;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Resources.ResourceManager rm ;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public MainWnd()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
//通过反射得到资源程序集
System.Reflection.Assembly asm = Assembly.GetExecutingAssembly();
//初始化资源管理对象
rm = new ResourceManager("ResourceConsumer.MyResources",asm);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LoadImg = new System.Windows.Forms.Button();
this.LoadString = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// LoadImg
//
this.LoadImg.Location = new System.Drawing.Point(112, 8);
this.LoadImg.Name = "LoadImg";
this.LoadImg.Size = new System.Drawing.Size(128, 23);
this.LoadImg.TabIndex = 0;
this.LoadImg.Text = "Load Image";
this.LoadImg.Click += new System.EventHandler(this.LoadImg_Click);
//
// LoadString
//
this.LoadString.Location = new System.Drawing.Point(552, 8);
this.LoadString.Name = "LoadString";
this.LoadString.Size = new System.Drawing.Size(112, 23);
this.LoadString.TabIndex = 1;
this.LoadString.Text = "Load String";
this.LoadString.Click += new System.EventHandler(this.LoadString_Click);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(8, 40);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(784, 368);
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// MainWnd
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(800, 413);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.LoadString);
this.Controls.Add(this.LoadImg);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "MainWnd";
this.Text = "ResourceConsumer";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainWnd());
}
private void LoadImg_Click(object sender, System.EventArgs e)
{
//从资源中提取字符串并显示
this.pictureBox1.Image = (Image)rm.GetObject("MyPic");
}
private void LoadString_Click(object sender, System.EventArgs e)
{
//从资源中提取字符串并显示
string str = (string)rm.GetString("MyString");
System.Windows.Forms.MessageBox.Show(str);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -