我正在尝试使用资源值做一些事情,但目前并不适合我。 我目前有一个使用图片框的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;更多推荐
发布评论