运行winforms时按钮图像没有出现 [英] button image is not comming while running a winforms

查看:82
本文介绍了运行winforms时按钮图像没有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#设计一个窗体。这里我有一个按钮,我正在尝试为它设置背景图像。图片来自设计师页面,但是在运行时它没有出现..

请帮帮我..

提前感谢.....

I am designing a windows form using c#. Here i have a button and i am trying to set a background image for it. The image is coming in designer page, but it is not appearing while running..
please help me..
thanks in advance.....

推荐答案

如果您创建图形文件资源如下:



1.上下文单击您的项目解决方案资源管理器树视图中的名称



2.选择菜单底部的属性菜单项



3.点击左边菜单中的资源项目



4.打开添加资源下拉菜单



5.选择添加现有文件项目



6.选择你的图形文件



然后,无论何时你想在代码中使用资源,你都会做类似的事情:
If you create a graphic file Resource like this:

1. context-click on your Project Name in the Solution Explorer treeview

2. select the Properties menu item at the bottom of the menu

3. click on the Resources item in the menu at left

4. open the Add Resource drop-down

5. select Add Existing File item

6. select your graphic file

Then, anytime you want to use the resource in code, you'll do something like:
button1.BackgroundImage = Properties.Resources.ResourceName;

只要输入Properties.Resources,Intellisense就会显示可用资源的名称。



如果这对您不起作用,那么请详细说明您如何将图形文件资源添加到项目中。

Intellisense should show you the names of available resources as soon as you have typed "Properties.Resources."

If that's not working for you, then please respond with details on exactly how you have added the graphic file resource to your Project.


好好查看代码为什么不是你替换你.BackgroundImage调用
Well looking at your code why don't you replace you .BackgroundImage call
this.button1.BackgroundImage = global::WindowsFormsApplication4.Properties.Resources.button1;

with



with

Bitmap bmp = new Bitmap(System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream("MyProject.Resources.myimage.png"));

this.button1.BackgroundImage = bmp;


这篇关于运行winforms时按钮图像没有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆