| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1344 人关注过本帖
标题:资源文件怎么使用?
只看楼主 加入收藏
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
结帖率:87.5%
收藏
 问题点数:0 回复次数:4 
资源文件怎么使用?
怎么嵌入和使用资源?大家可以给个简单的实例吗?
资源文件到底怎么用啊?请大家帮帮我
搜索更多相关主题的帖子: 资源文件 实例 asp 
2008-04-23 10:46
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
自己顶一下!
没人做过嵌入资源吗?高手进来指点一下吧!
2008-04-26 09:10
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
再顶一下,没一个人会吗?
2008-04-28 08:26
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
资源文件怎么使用?这么多人,没一人知道吗?怎么没人理我?
2008-05-28 16:05
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
网上找的例子,要我说也一时半会说不清楚,这个例子应该会对你有帮助的
程序代码:
using System; 
  using System.Drawing; 
  using System.Collections; 
  using  
  using System.Windows.Forms; 
  using System.Data; 
  using System.Reflection; 
  using  
  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  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\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); 
   } 
   } 
  }
2008-05-28 17:38
快速回复:资源文件怎么使用?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018841 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved