簡體   English   中英

如何從我的resx文件中檢索圖像?

[英]How do I retrieve an image from my resx file?

我已經在我的表單的資源文件myForm.resx中添加了一個圖像,我想在我的代碼文件myForm.cs中使用它,但我並不完全清楚如何獲取它的句柄。

您可以使用Visual Studio添加它(項目,屬性,資源,添加現有文件),然后按名稱訪問它:

   Bitmap bmp = Properties.Resources.<name_you_gave_it>;

請參閱MSDN for ResourceManager

rm = new ResourceManager("Images", this.GetType().Assembly); 
pictureBox1.Image = (System.Drawing.Image)rm.GetObject("flag");

從此鏈接提取以下代碼

// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new 
   System.Resources.ResourceManager("ResourceNamespace.myResources", 
   myAssembly);

// Retrieves String and Image resources.
System.String myString;
System.Drawing.Image myImage;
myString = myManager.GetString("StringResource");
myImage = (System.Drawing.Image)myManager.GetObject("ImageResource");
pictureBox1.Image = new Bitmap (global::<<project namespace>>.Properties.Resources.<<Filename>>);

如下所示,我實施的那個:

pboxSignedInStaffIcon.Image = new Bitmap(global::EasyRent.Properties.Resources.worker1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM