使用C#使用动态标签 [英] using dynamic label using C#
本文介绍了使用C#使用动态标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#在中创建动态标签
解决方案
public partial class newTemplate:Form
{
int i = 0 ;
int x = 22 ;
int noofcontrols = 0 ;
TextBox [] t1 = new TextBox [ 25 ];
标签[] l1 = 新标签[ 25 ];
public newTemplate()
{
InitializeComponent();
}
。
。
。
}
这里我按钮点击创建标签,你可以按照你的要求去做
private void button2_Click( object sender,EventArgs e)
{
t1 [i] = new TextBox();
l1 [i] = new 标签();
t1 [i] .Size = new System.Drawing.Size( 244 , 22 );
t1 [i] .Location = new System.Drawing.Point( 85 ,x) ;
l1 [i] .Location = new System.Drawing.Point( 60 , X);
l1 [i] .Font = new System.Drawing.Font( Microsoft Sans Serif,9F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,(( byte )( 0 )));
l1 [i] .Text = i.ToString()+ 。;
// t [i] .Name = drform [0] .ToString ();
t1 [i] .TabIndex = i;
t1 [i] .Name = txt + i;
panel1.Controls.Add(t1 [i]);
panel1.Controls.Add(l1 [i]);
panel1.AutoSize = true ;
panel1.Show();
panel1.Refresh();
t1 [i] .focus();
i ++;
x = x +30;
noofcontrols ++;
}
尝试
public void AddMyControls()
{
TextBox textBox1 = new TextBox();
Label label1 = new Label();
//初始化控件及其边界。
label1.Text =Text label1.Location = new Point(48,48);
label1.Size = new Size(104,16);
//添加标签控件到窗体的控件集合。
Controls.Add(label1);
}
标签lbl = new Label();
lbl.Text =lable add;
lbl.AutoSize = true;
lbl.ForeColor = Color.Red;
lbl.Location = new Point(850,335); //在此设置你的欲望位置
this.Controls.Add(lbl);
lbl .BringToFront();
How to Create dynamic lable in windows application using c#
解决方案
public partial class newTemplate : Form { int i = 0; int x = 22; int noofcontrols = 0; TextBox[] t1 = new TextBox[25]; Label[] l1 = new Label[25]; public newTemplate() { InitializeComponent(); } . . . }
here i am creating labels on button click, you can do as your requirement
private void button2_Click(object sender, EventArgs e) { t1[i] = new TextBox(); l1[i] = new Label(); t1[i].Size = new System.Drawing.Size(244, 22); t1[i].Location = new System.Drawing.Point(85, x); l1[i].Location = new System.Drawing.Point(60, x); l1[i].Font =new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); l1[i].Text = i.ToString()+". "; // t[i].Name = drform[0].ToString(); t1[i].TabIndex = i; t1[i].Name = "txt"+i; panel1.Controls.Add(t1[i]); panel1.Controls.Add(l1[i]); panel1.AutoSize = true; panel1.Show(); panel1.Refresh(); t1[i].Focus(); i++; x = x +30 ; noofcontrols++; }
Try
public void AddMyControls() { TextBox textBox1 = new TextBox(); Label label1 = new Label(); // Initialize the controls and their bounds. label1.Text = "Text label1.Location = new Point(48,48); label1.Size = new Size (104, 16); // Add the Label control to the form's control collection. Controls.Add(label1); }
Label lbl = new Label();
lbl.Text = "lable add";
lbl.AutoSize = true;
lbl.ForeColor = Color.Red;
lbl.Location = new Point(850, 335); //set ur desire loction here
this.Controls.Add(lbl);
lbl.BringToFront();
这篇关于使用C#使用动态标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文