动态按钮 [英] Dynamic Buttons
问题描述
先生,
先生,我正在使用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不支持文本
抛出这样的错误
请帮助我并建议
按钮有一个内容属性,你可以把文本块放在
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
这篇关于动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!