当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  在.NET中嵌入和使用资源文件

 在.NET中嵌入和使用资源文件

点击次数:20 次 发布日期:2008-11-26 11:51:15 作者:源代码网
源代码网推荐      嵌入和使用资源文件,以下是全部源代码:
源代码网推荐  
源代码网推荐  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>
源代码网推荐   /// Summary description for Form1.
源代码网推荐   /// </summary>
源代码网推荐   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;
源代码网推荐   /// <summary>
源代码网推荐   /// Required designer variable.
源代码网推荐   /// </summary>
源代码网推荐   private System.ComponentModel.Container components = null;
源代码网推荐  
源代码网推荐   public Form1()
源代码网推荐   {
源代码网推荐   //
源代码网推荐   // Required for Windows Form Designer support
源代码网推荐   //
源代码网推荐   InitializeComponent();
源代码网推荐  
源代码网推荐   // Instantiate our ArrayList
源代码网推荐   pics = new ArrayList();
源代码网推荐   }
源代码网推荐  
源代码网推荐   /// <summary>
源代码网推荐   /// Clean up any resources being used.
源代码网推荐   /// </summary>
源代码网推荐   protected override void Dispose( bool disposing )
源代码网推荐   {
源代码网推荐   if( disposing )
源代码网推荐   {
源代码网推荐   if (components != null)
源代码网推荐   {
源代码网推荐   components.Dispose();
源代码网推荐   }
源代码网推荐   }
源代码网推荐   base.Dispose( disposing );
源代码网推荐   }
源代码网推荐  
源代码网推荐   #region Windows Form Designer generated code
源代码网推荐   /// <summary>
源代码网推荐   /// Required method for Designer support - do not modify
源代码网推荐   /// the contents of this method with the code editor.
源代码网推荐   /// </summary>
源代码网推荐   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
源代码网推荐  
源代码网推荐   /// <summary>
源代码网推荐   /// The main entry point for the application.
源代码网推荐   /// </summary>
源代码网推荐   [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 ", resNames.Length);
源代码网推荐   txtInfo.Text += "---------- ";
源代码网推荐   foreach(string s in resNames)
源代码网推荐   {
源代码网推荐   txtInfo.Text += s + " ";
源代码网推荐   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 += "---------- ";
源代码网推荐   txtInfo.Text += String.Format("Found {0} Bitmaps ",
源代码网推荐   pics.Count);
源代码网推荐   }
源代码网推荐   }
源代码网推荐  }
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华