[英]How do I generate an Image through C# code?
I've got a button in my WinForms plugin.我的 WinForms 插件中有一个按钮。 It's got an image on it.它上面有图像。 The thing is, when I click the button, I want the image to change from whatever image it is now, to whatever image I want it to be.问题是,当我单击按钮时,我希望图像从现在的任何图像变为我想要的任何图像。
So basically how do i make button change its image?所以基本上我如何让按钮改变它的形象? The image type is System.Drawing.Image
.图像类型是System.Drawing.Image
。
In order to change a Button
's image in WinForms you set it's Image
property.为了在 WinForms 中更改Button
的图像,您需要设置它的Image
属性。 You can either load a bitmap from a file with Bitmap.FromFile
, or you can draw an image using the Graphic
class by creating a new instance of Bitmap using the Width/Height constructor (ie new Bitmap(100, 100)
) and then use the Graphic.FromImage
method. You can either load a bitmap from a file with Bitmap.FromFile
, or you can draw an image using the Graphic
class by creating a new instance of Bitmap using the Width/Height constructor (ie new Bitmap(100, 100)
) and then use Graphic.FromImage
方法。 Lookup the documentation on the Graphic
class for more info.在Graphic
class 上查找文档以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.