All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET常用JS脚本整理_[Asp.Net教程]
C—sharp开发应避免的几个小滥用_[Asp.Net教程]
PHPUnit袖珍指南之PHPUnit的目的_[PHP教程]
HTML 初学者指南(1)_[Html教程]
ASP.NET从零起步设计网站全过程(9)_[Asp.Net教程]
delphi组件VCL运行机制
详细介绍PHP动态网页技术中SESSION的应用_php资料_编程技术
SQL Server 2000中的触发器使用分析_[SQL Server教程]
优化SQL Server数据库的方法_[SQL Server教程]
从Access数据库到SQL Server高手_[SQL Server教程]
Reading number is top 10 pictures
做运动的校花1
Exquisite decoration is not paying too much1
A letter to parents choose world of warcraft seven big reason
美女和狗狗2
乳娘帕梅拉安德森1
Thrilling English baby
每天进步一点点
西游日记4
The money of more than 100 countries and regions12
The household of rural style is designed
Download software ranking
Prostitutes diary
Unix video tutorial3
Unix video tutorial2
Proficient in Eclipse
传奇私服架设教程
The king of fighters 97(Mobile phone games-apk)
Tram sex maniac 2 (H) rar bag19
Visual C++界面编程技术
The Bermuda triangle2
传奇私服架设教程
delv published in(发表于) 2014/1/23 3:14:16 Edit(编辑)
在.NET中嵌入和使用资源文件_[Asp.Net教程]

在.NET中嵌入和使用资源文件_[Asp.Net教程]

在.NET中嵌入和使用资源文件_[Asp.Net教程]

嵌入和使用资源文件,以下是全部源代码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace ResourceDemo
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
ArrayList pics;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.PictureBox pBox;
private System.Windows.Forms.Button btnDisplay;
private System.Windows.Forms.TextBox txtInfo;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

// Instantiate our ArrayList
pics = new ArrayList();
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.pBox = new System.Windows.Forms.PictureBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnDisplay = new System.Windows.Forms.Button();
this.txtInfo = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// pBox
//
this.pBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pBox.Location = new System.Drawing.Point(8, 8);
this.pBox.Name = "pBox";
this.pBox.Size = new System.Drawing.Size(264, 272);
this.pBox.TabIndex = 0;
this.pBox.TabStop = false;
this.pBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtInfo,
this.btnDisplay});
this.groupBox1.Location = new System.Drawing.Point(288, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(192, 264);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// btnDisplay
//
this.btnDisplay.Location = new System.Drawing.Point(48, 24);
this.btnDisplay.Name = "btnDisplay";
this.btnDisplay.Size = new System.Drawing.Size(96, 23);
this.btnDisplay.TabIndex = 0;
this.btnDisplay.Text = "Display Picture";
this.btnDisplay.Click += new System.EventHandler(this.button1_Click);
//
// txtInfo
//
this.txtInfo.Location = new System.Drawing.Point(8, 56);
this.txtInfo.Multiline = true;
this.txtInfo.Name = "txtInfo";
this.txtInfo.ReadOnly = true;
this.txtInfo.Size = new System.Drawing.Size(176, 200);
this.txtInfo.TabIndex = 2;
this.txtInfo.Text = "txtInfo";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(496, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1,
this.pBox});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
// go to a random picture in our arraylist and
// display it
Random generator = new Random();
Bitmap bmp = pics[ generator.Next(pics.Count) ] as Bitmap;
if(!(null==bmp))
{
pBox.Image = bmp;
}
bmp = null;
generator = null;
}

private void Form1_Load(object sender, System.EventArgs e)
{
Stream imgStream = null;
Bitmap bmp = null;

// get a reference to the current assembly
Assembly a = Assembly.GetExecutingAssembly();

// get a list of resource names from the manifest
string [] resNames = a.GetManifestResourceNames();

// populate the textbox with information about our resources
// also look for images and put them in our arraylist
txtInfo.Clear();

txtInfo.Text += String.Format("Found {0} resources\r\n", resNames.Length);
txtInfo.Text += "----------\r\n";
foreach(string s in resNames)
{
txtInfo.Text += s + "\r\n";
if(s.EndsWith(".bmp"))
{
// attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStream(s);
if( !(null==imgStream) )
{
// create a new bitmap from this stream and
// add it to the arraylist
bmp = Bitmap.FromStream( imgStream ) as Bitmap;
if( !(null==bmp) )
{
pics.Add( bmp );
}
bmp = null;
imgStream.Close();
imgStream = null;
}
}
}
txtInfo.Text += "----------\r\n";
txtInfo.Text += String.Format("Found {0} Bitmaps\r\n",
pics.Count);
}
}
}








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.