zoukankan      html  css  js  c++  java
  • C#调用Resources.resx资源文件中的资源

    使用到了.NET中的资源文件,也就是Resources.resx,于是就学会了如何调用资源文件中的资源。
    首先,资源文件可以从项目属性中的资源标签添加。比如,我添加一个图片,叫做aaa.png,添加入资源文件后,可以给他命名,比如叫它aaa。如此,添加文件就完成了。
    然后,在程序中调用,只需要一句话:
    Properties.Resources.资源名
    比如我刚添加的图片,就写Properties.Resources.aaa就ok了,当然在IDE中写代码的时候是会有提示的。
    最后,没了,就这么简单。
    充篇幅,放一段代码,来证明调用真的很简单:
            private void FormMain_Load(object sender, EventArgs e)
            {
                serviceController1.ServiceName = "XXX";//这是一个windows服务的名字
                switch (serviceController1.Status)
                {
                    case ServiceControllerStatus.Stopped:
                        {
                            //pbxServer是一个PictureBox组件
                            //ServerStop,ServerStart,Server分别是三张图片
                            pbxServer.Image = Properties.Resources.ServerStop;
                            break;
                        }
                    case ServiceControllerStatus.Running:
                        {
                            pbxServer.Image = Properties.Resources.ServerStart;
                            break;
                        }
                    default:
                        {
                            pbxServer.Image = Properties.Resources.Server;
                            break;
                        }
                }
            }
    斗争了很久,到底要不要记在这里,因为调用资源实在很简单;可是我也确实费了好大劲才知道怎么用的。
    最后还是决定记下来,因为实在信不过自己的脑子……
    ————————————————
    版权声明:本文为CSDN博主「MuteG」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/gaoyunpeng/java/article/details/2882009

  • 相关阅读:
    poj 2312 Battle City
    poj 2002 Squares
    poj 3641 Pseudoprime numbers
    poj 3580 SuperMemo
    poj 3281 Dining
    poj 3259 Wormholes
    poj 3080 Blue Jeans
    poj 3070 Fibonacci
    poj 2887 Big String
    poj 2631 Roads in the North
  • 原文地址:https://www.cnblogs.com/net-sky/p/12767182.html
Copyright © 2011-2022 走看看