2012-04-16 128 views
0

如何在按钮数组的按钮上添加图像?C#如何在按钮阵列按钮上添加图像

Button[] mybuttons = new Button[] {Button1,Button2}; //My button array 

mybuttons[1].image=new Bitmap("Click.jpg"); ///Gives Error 

“System.Web.UI.WebControls.Button”不包含“图像”和没有扩展方法“图像”接受型的第一参数“的定义System.Web.UI.WebControls.Button '可以找到(你是否缺少使用指令或程序集引用?)

回答

1

C#区分大小写。此外,您需要使用ImageButton并为其指定ImageUrl,而不是Button。 Web控件Button没有Image属性。

+0

但是,我需要使用没有imagebutton属性的按钮数组。 – 2012-04-16 23:25:34

+0

然后恐怕你运气不好,Button类在你编写Windows Forms应用程序时只有一个Image属性。 Windows窗体应用程序使用此按钮类,http://msdn.microsoft.com/en-us/library/system.windows.forms.button.aspx。您不能在ASP.NET中使用System.Windows.Forms.Button类。在ASP.NET Web应用程序中,Button类来自System.Web.UI.WebControls,根本不实现Image属性。 – JamieSee 2012-04-17 15:56:41