动态按钮 [英] Dynamic Buttons

查看:57
本文介绍了动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,


先生,我正在使用Visual Studio 2010,我是应用程序开发的新手。


我正在创建一个我已经在新页面中存储了数据库中的学生数量的应用程序我想添加尽可能多的学生已注册的按钮.........以便在点击按钮时为特定学生提供新的页面的详细信息可能会打开


问题是每次添加新学生时我都要再添加1个按钮...我认为按钮是动态添加的,代码是在  .xaml.cs文件中..................


我试过这段代码 

 

private void BtnGenerate_Click object sender EventArgs e
{
for int i = 0 ; i < 8 ; i ++)
{
按钮 按钮 = new 按钮 ();
按钮
Text = " Button" + i ToString ();
按钮
位置 = new Point 0 button Height * i );
this lstViewButton Controls Add button );
}
}

但问题显示错误System.Windows.Controls.Button不支持文本

抛出这样的错误

请帮助我并建议

解决方案

按钮有一个内容属性,你可以把文本块放在



http://msdn.microsoft.com/en-us/library/system.windows。 controls.contentcontrol.content(v = vs.110)的.aspx


sir,

Sir I am using visual studio 2010 and i'm new in app development.

I am creating an app in which i have stored the no of students in database in a new page i want to add as many buttons as many students have registered .........so that on clicking button for  a particular student a new page for their details may open

problem is each time a new student is added i have to add 1 more 1 button...I think buttons are to be added dynamically and code is to be in the  .xaml.cs file..................

I tried this code 

private void BtnGenerate_Click(object sender, EventArgs e) { for (int i = 0; i < 8; i++) { Button button = new Button(); button.Text = "Button" + i.ToString(); button.Location = new Point(0, button.Height*i); this.lstViewButton.Controls.Add(button); } }

But problem it shows Error System.Windows.Controls.Button does not support Text

something like this error is thrown

Please help me and suggest

解决方案

Button has a content property you can put a textblock in

http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.content(v=vs.110).aspx


这篇关于动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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