• 网络学院
  • IT资讯
  • 操作系统
  • 网络技术
  • 软件应用
  • 办公软件
  • 编程技术
  • 网站架设
  • 数据库类
  • 平面设计
  • 多媒体类
  • 游戏资讯
  • 教学论文
  • 认证考试
在.NET中嵌入和使用资源文件
  站点:
  • 首 页
  • 最新软件
  • 文章教程
  • 国内软件
  • 国外软件
  • 绿色软件
  • 源码下载
  • 字体下载
在.NET中嵌入和使用资源文件
软件发布 在.NET中嵌入和使用资源文件
网络软件 系统工具 应用软件 联络聊天 图形图像 多媒体类 行业软件 游戏娱乐 编程开发 安全相关 教育教学 数码软件 绿软下载
热门软件: QQ 瑞星 pplive e话通 木马克星 千千静听 office2000 五笔字根 Photoshop 视频分割
返回文章教程首页 >> 文章首页 >> 编程技术 >> C#教程 >> 在.NET中嵌入和使用资源文件

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

添加时间: 2007-7-13 1:53:24  作者: C#教程  阅读次数:75   来源: http://www.d9soft.com

       

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

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.<a href="http://dev.21tx.com/os/windows/" target="_blank">Windows</a>.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.Grou<a href="http://dev.21tx.com/language/pb/" target="_blank">PB</a>ox 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\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);                       
        }
    }
}

 

上下文章:

 

上一篇文章: 用C#实现木马程序分析 下一篇文章: 利用WebClient类向服务器上载文件

相关文章:

  • 新蠕虫伪装成文件夹图标,让你防不胜防
  • Vista找不到Config文件夹的解决办法
  • 病毒猖獗,怎么打开电脑文件会较安全?
  • 使用搜狗音乐盒下载歌曲,快带飚的体验
  • 教你如何使用Procmail 过滤mail病毒

相关软件:

  • 文件管理精灵 V3.21
  • 全国计算机等级考试模拟软件(2006年全年使用)二级Visual Basic V9.0
  • FTP远程文件同步更新程序 1.0.0.0
  • 系统文件备份工具 1.0a
  • excel文件转marc文件工具 V2.5
  • Excel文件转换 V0.5

 

快速导航

  • 网络学院
  • 精品汇聚
  • 字体下载
  • 教程下载
  • ASP源码
  • PHP源码
  • Net源码
  • JSP 源码

编程技术分类导航

  • ASP & ASP.NET教程
  • PHP教程
  • JSP教程
  • C/C++教程
  • VB & VB.NET教程
  • VC教程
  • Delphi教程
  • BCB教程
  • VFP教程
  • PB教程
  • JAVA教程
  • XML教程
  • C#教程
  • CGI教程

本类经典文章推荐

  • ADO.NET的开发场景及传统ADO的处理
  • 利用Visual C#实现Window管道技术
  • C#取得汉字的拼音的首字母
  • 使用C#编写DES加密程序的framework
  • Visual C#编写3D游戏框架示例
  • 用C#和本地Windows API操纵系统菜...
  • 在C#程序设计中使用Win32类库
  • Visual C#中调用Windows服务初探
  • 如何在C#的WinForm中制作饼状图和...
  • C#中实现DataGrid双向排序

C#教程阅读排行

  • 如何在C#的WinForm中制作饼状图和...
  • 浅析C#中图形编程
  • 用C#和本地Windows API操纵系统菜...
  • 彻底剖析C# 2.0泛型类的创建和使用
  • 使用C#编写DES加密程序的framework
  • Visual C#编写3D游戏框架示例
  • Visual C#中调用Windows服务初探
  • C#如何在Form中嵌入并且操作Excel...
  • Visual C# 2005实现控件中捕获按键
  • C#中利用mediaplayer打造mp3播放器

编程技术阅读总排行

  • VB入门教程之一
  • Java连接数据库实例
  • 第二章 PowerBuilder 入门之创建新...
  • VC++之List Box/Check List Box控...
  • 第一章 什么是PowerBuilder
  • VC++ List Ctrl控件
  • VC++ Combo Box/Combo Box Ex控件
  • 学C++不得不看的一篇文章
  • VB入门教程之二
  • VC++之Button控件

广告位置

字母检索 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 回到顶部

关于我们 | 版权声明 | 免责条款 | 广告联系 | 软件发布 | 下载帮助 | 下载排行 | 网站地图 | 特别鸣谢 | 友情连接

copyright; 2005-2008 D9soft.com 第九软件网 版权所有