C#基于方法返回值设置资源值(C# set resource value based on method return value)

编程入门 行业动态 更新时间:2024-10-28 01:18:14
C#基于方法返回值设置资源值(C# set resource value based on method return value)

我正在尝试使用资源值做一些事情,但目前并不适合我。 我目前有一个使用图片框的Windows窗体应用程序。 我在项目资源(X和Y)中设置了两张图片。

我想要实现的目标如下:

pictureBoxTurn.Image = Properties.Resources.( either X or Y goes here hard-coded );

我有一个方法,根据某些检查返回X或Y. 我试图将返回值放在那里而不是硬编码的部分。

pictureBoxTurn.Image = Properties.Resources.( returned X/Y );

我正在考虑将返回值放在本地var中,我可以使用它来代替硬编码的部分。 如果我不清楚,我很抱歉,但我不知道如何搜索这个问题。 我尝试过,但是根本找不到类似的问题。

我还在学习,所以我的方式并不完美。 感谢您阅读我的问题!

I am trying to do something using Resource values but it isn't really working out for me at the moment. I currently have a Windows Forms application which uses a picturebox. I have two pictures set in my project resources ( X and Y ).

What i'm trying to achieve is the following :

pictureBoxTurn.Image = Properties.Resources.( either X or Y goes here hard-coded );

I have a method which returns X OR Y based on certain checks. I'm trying to put the return value up there instead of the hard-coded piece.

pictureBoxTurn.Image = Properties.Resources.( returned X/Y );

I was thinking about putting the return value in a local var, which I could use instead of the hard-coded piece. I'm sorry if I am being unclear but I have no idea on how to search for this problem. I tried, but simply enough couldn't find similar questions.

I'm still learning so my ways aren't perfect. Thank you for reading my question!

最满意答案

string imageToReturn = GetImageToReturn(); object obj = Properties.Resources.ResourceManager.GetObject(imageToReturn, resourceCulture); pictureBoxTurn.Image = (System.Drawing.Bitmap)obj; string imageToReturn = GetImageToReturn(); object obj = Properties.Resources.ResourceManager.GetObject(imageToReturn, resourceCulture); pictureBoxTurn.Image = (System.Drawing.Bitmap)obj;

更多推荐

本文发布于:2023-07-23 22:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   方法   资源   set   return

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!