制作一个Dll输入所有图标和图像及其中的资源并在代码中使用它 [英] Making A Dll To Input All Icon And Images And .. Resources in it and use it in code

查看:73
本文介绍了制作一个Dll输入所有图标和图像及其中的资源并在代码中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,

我想创建仅包含资源的DLL,我该如何使用它?

如何在c#Windows窗体中获取不同情况下的资源代码,

谢谢所有

Hello Experts ,
I want to make DLL That Contains Only Resources , And How Can I use It?
How Can Get Resources In Different Situation In c# Windows Form Code ,
Thanks all

推荐答案





是的,它有可能做到这一点。创建一个新项目(类库),并为其添加资源。 资源类是一个内部类,所以你不能在另一个项目中使用它。因此,在类库项目中添加一个静态类, GetResources

Hi,

Yes, it''s possible to do that. Create a new project (Class Library), and add resources to it. The Resources class is an internal class, so you can''t use it in another project. So, add a static class in your Class Library projects, GetResources:
public static class GetResources
{
      public static object GetObject(string name)
      {
           return Properties.Resources.ResourceManager.GetObject(name);
      }
      public static string GetString(string name)
      {
           return Properties.Resources.ResourceManager.GetString(name);
      }
      public static System.Resources.ResourceManager GetResourceManager()
      {
           return Properties.Resources.ResourceManager;
      }
}



在您的其他项目中,添加对此类库的引用。要在类库的资源中获取字符串String1的值,可以使用以下代码:


And in your other project, add a reference to this Class Library. To get the value of the string "String1" in the resources of your Class Library, you can use this code:

string string1 = GetResources.GetString("String1");



要获取图像Image1,请使用以下代码:


To get an image "Image1", use this code:

Bitmap bmp = GetResources.GetObject("Image1") as Bitmap;



希望这有帮助。


Hope this helps.


我强烈建议添加暴露这些资源的代码,以获得正确的封装方法。



-SA
I would strongly advise to add the code exposing those resources, for proper encapsulated approach.

—SA


这篇关于制作一个Dll输入所有图标和图像及其中的资源并在代码中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆