在 C# 中设置按钮的背景图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17603272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting background image of button in C#
提问by TheMrRafus
I want to set an image as background of a button of Windows Forms.
我想将图像设置为 Windows 窗体按钮的背景。
The image is added to the project′s resources.
图像将添加到项目的资源中。
How do I do this?
我该怎么做呢?
回答by dsfgsho
Simply set the BackgroundImageproperty of the Button. An example:
只需设置按钮的BackgroundImage属性。一个例子:
button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));
回答by Kyle Colantonio
You would use this when you load your application, or whenever you want to set it.
当你加载你的应用程序时,或者你想设置它时,你会使用它。
button.BackgroundImage = YourApplicationNamespace.Properties.Resources.yourImageHere;
回答by Brian
In Visual Studio, you can do this:
在 Visual Studio 中,您可以执行以下操作:
- Go to the properties for your button and click the
BackgroundImageitem. - Click the '...' icon.
- Click the radio button next to 'Local Resource'.
- Click 'Import' and select the item you wish to have as the background.
- Then, click 'Ok'.
- 转到按钮的属性并单击该
BackgroundImage项目。 - 单击“...”图标。
- 单击“本地资源”旁边的单选按钮。
- 单击“导入”并选择您希望作为背景的项目。
- 然后,单击“确定”。
Or, from code you can do this:
或者,您可以从代码中执行以下操作:
button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));

