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

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

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

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

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

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

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

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

            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之后使用的是控件自带的添加图片的方法使用图片资源。图片

相关文章
相关标签/搜索