项目资源文件的添加与使用

在项目使用的图片,字符串等资源文件,在使用前首先添加到项目的资源文件,在使用时使用如下命令进行添加:

this.imageList1.ImageStream = ((ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));

以上命令添加了一个imagelist资源。把图片资源从资源文件获取来,添加到程序界面。

this.imageList1.Images.SetKeyName(0, "close");

使用以上命令指定使用哪一个图片文件。

同时也可以使用控件自带的添加图片的功能,右键点击该控件,选择添加图片添加图片。但是使用资源文件的方式使得整个程序更加的统一,利于管理。而且可以再其他界面对资源文件进行多次的重复使用。因此本人推荐使用资源文件。

资源文件的添加很简单,打开项目,双击property文件夹,就会弹出项目的属性,选择资源,就出现了项目包含的所有资源文件。按照资源的类型进行添加。比如要添加图片,选择资源类型为图片,然后找到要添加的图片,拖入该窗口即可。 

            this.imageList1.ImageStream = ((ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));

            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;

            this.imageList1.Images.SetKeyName(0, "close");

            this.imageList1.Images.SetKeyName(1, "max");

            this.imageList1.Images.SetKeyName(2, "min");

            this.imageList1.Images.SetKeyName(3, "normal");

            this.imageList1.Images.SetKeyName(4, "CameraDisconn");

            this.imageList1.Images.SetKeyName(5, "CameraConn");

            this.imageList1.Images.SetKeyName(6, "CameraSeach");

            this.imageList1.Images.SetKeyName(7, "IOSearch");

            this.imageList1.Images.SetKeyName(8, "IOCon.bmp");

            this.imageList1.Images.SetKeyName(9, "IODiscon.bmp");

            this.imageList1.Images.SetKeyName(10, "search.bmp");

            this.imageList1.Images.SetKeyName(11, "right.bmp");

            this.imageList1.Images.SetKeyName(12, "err.bmp");

            this.imageList1.Images.SetKeyName(13, "waiting.bmp");
View Code

以上是两种方式使用图片资源,8之前使用的是项目的资源文件,8以后使用的是控件自带的添加图片的方法使用图片资源。

posted @ 2018-08-27 07:51  火锅商人  阅读(302)  评论(0编辑  收藏  举报