int a = 0; int x = 0, y = 0; Label[] l = new Label[100]; TextBox[] n = new TextBox[100]; for (a = 0; a <= 99; a++) { l[a] = new Label(); l[a].Text = "Label" + a + ":"; l[a].Width = (panel1.Width - 20) / 4; l[a].Left = x * l[a].Width; l[a].Height = 21; l[a].Top = y * l[a].Height; l[a].TextAlign = ContentAlignment.MiddleRight; Debug.Write("l[" + a + "]:\n"); Debug.Write("Width" + l[a].Width + "\n"); Debug.Write("Left" + l[a].Left + "\n"); Debug.Write("Height" + l[a].Height + "\n"); Debug.Write("Top" + l[a].Top + "\n"); Debug.Write(""); panel1.Controls.Add(l[a]); x += 1; n[a] = new TextBox(); n[a].Width = (panel1.Width - 20) / 4; n[a].Left = x * n[a].Width; n[a].Height = 21; n[a].Top = y * n[a].Height; n[a].Text = "Text" + a; Debug.Write("n[" + a + "]:\n"); Debug.Write("Width" + n[a].Width + "\n"); Debug.Write("Left" + n[a].Left + "\n"); Debug.Write("Height" + n[a].Height + "\n"); Debug.Write("Top" + n[a].Top + "\n"); panel1.Controls.Add(n[a]); x += 1; if (x == 4) { x = 0; y += 1; } }
标记处TCP IP等等字样 是标记出吧,错字很害人的就是动态生成控件吧, using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;namespace WindowsApplication21 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.comboBox1.Items.Add("tcp"); this.comboBox1.Items.Add("udp");
能有人知道怎么做吗?我现在c#也就入门吧,没有头绪啊
好象不用“生成”吧?
int a = 0;
int x = 0, y = 0;
Label[] l = new Label[100];
TextBox[] n = new TextBox[100];
for (a = 0; a <= 99; a++)
{
l[a] = new Label();
l[a].Text = "Label" + a + ":";
l[a].Width = (panel1.Width - 20) / 4;
l[a].Left = x * l[a].Width;
l[a].Height = 21;
l[a].Top = y * l[a].Height;
l[a].TextAlign = ContentAlignment.MiddleRight;
Debug.Write("l[" + a + "]:\n");
Debug.Write("Width" + l[a].Width + "\n");
Debug.Write("Left" + l[a].Left + "\n");
Debug.Write("Height" + l[a].Height + "\n");
Debug.Write("Top" + l[a].Top + "\n");
Debug.Write("");
panel1.Controls.Add(l[a]);
x += 1;
n[a] = new TextBox();
n[a].Width = (panel1.Width - 20) / 4;
n[a].Left = x * n[a].Width;
n[a].Height = 21;
n[a].Top = y * n[a].Height;
n[a].Text = "Text" + a;
Debug.Write("n[" + a + "]:\n");
Debug.Write("Width" + n[a].Width + "\n");
Debug.Write("Left" + n[a].Left + "\n");
Debug.Write("Height" + n[a].Height + "\n");
Debug.Write("Top" + n[a].Top + "\n");
panel1.Controls.Add(n[a]);
x += 1;
if (x == 4)
{
x = 0;
y += 1;
}
}
是标记出吧,错字很害人的就是动态生成控件吧,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace WindowsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("tcp");
this.comboBox1.Items.Add("udp");
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.panel1.Controls.Clear();
Label lbl = new Label();
this.panel1.Controls.Add(lbl);
lbl.Text = comboBox1.SelectedItem.ToString();
lbl.Name = "lbl" + lbl.Text;
lbl.Top = this.panel1.Top;
lbl.Width = 50;
lbl.Height = 20;
TextBox tb = new TextBox();
this.panel1.Controls.Add(tb);
tb.Text = "";
tb.Name = "tb" + lbl.Text;
tb.Top = lbl.Top;
tb.Left = lbl.Right + 10;
tb.Width = 200;
tb.Height = 20; }
}
public class ListItem
{ private string textField; public string TextField
{
get { return textField; }
set { textField = value; }
} private string valueField; public string ValueField
{
get { return valueField; }
set { valueField = value; }
}
}
//下面绑定
}
private Point lblPoint = new Point(50, 50);
private Point txtPoint = new Point(200, 50);
public Form1()
{
InitializeComponent();
} private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
//动态给数组添东西,我随便写的二维数组
System.Int32 num = this.comboBox1.Items.Count;
System.String[][] str= new System.String[num][];
for (System.Int32 i = 0; i < num; i++)
{
str[i] = new System.String[] { this.comboBox1.Items[i].ToString(), "1" };
}
//查找数组中的值
System.String strFirst = "";
System.String strSecond = "";
System.String strSelected = this.comboBox1.SelectedItem.ToString();
for (System.Int32 j = 0; j < num; j++)
{
if (strSelected.Equals(str[j][0]))
{
strFirst = str[j][0];
strSecond = str[j][1];
}
}
//生成Label
Label myLable = new Label();
myLable.Location = lblPoint;
myLable.Text = strFirst;
this.Controls.Add(myLable);
//生成TextBox
TextBox txtBox = new TextBox();
txtBox.Location = txtPoint;
txtBox.Text = strSecond.ToString();
this.Controls.Add(txtBox);
//重设位置
lblPoint = new Point(lblPoint.X, lblPoint.Y + 30);
txtPoint = new Point(txtPoint.X, txtPoint.Y + 30);
}
不知道你要的是不是这样动态生成的
有n个数组:(这n个数组是我从数据库里读出来的),当我选中一个数组a[i][2]时;
进行如下动态生成:
其中a[i][0]代表在界面上所要显示的lebal中的内容,a[i][1]就是最大可输入的数字。
我需要i从0到i-1,依次遍历,这样就在界面上有好多行“lebal ------textbox”的东西了。 上面的a,就是相当于tcp,而当选mgcp的时候,相当于我又选了一个数组b[j][2];
注:其中所有的数组都是x[k][2]的结构,都是我从数据库读出来的,这里就当作已有的,随便定义几个就行。并且x[j][0]是字符串,用来显示lebal;x[j][1]是int型数字,就是textbox的最大输入而已。(0 <= j <= k-1) 这就是我的最终问题 应该是算动态生成的吧,因为那些数组是我从数据库读的,不能确定k的数目,所以只有动态生成。真的麻烦了,就要答辩,所以急了些
有n个数组:(这n个数组是我从数据库里读出来的),当我选中一个数组a[i][2]时;
进行如下动态生成:
其中a[i][0]代表在界面上所要显示的lebal中的内容,a[i][1]就是最大可输入的数字。
我需要i从0到i-1,依次遍历,这样就在界面上有好多行“lebal ------textbox”的东西了。 上面的a,就是相当于tcp,而当选mgcp的时候,相当于我又选了一个数组b[j][2];
注:其中所有的数组都是x[k][2]的结构,都是我从数据库读出来的,这里就当作已有的,随便定义几个就行。并且x[j][0]是字符串,用来显示lebal;x[j][1]是int型数字,就是textbox的最大输入而已。(0 <= j <= k-1) 这就是我的最终问题 我需要的应该是动态生成的吧,因为数组是我从数据库读出来的,k是不确定的,所以应该是动态生成的吧真的麻烦了,就要答辩,所以急了些
有n个数组:(这n个数组是我从数据库里读出来的),当我选中一个数组a[i][2]时;
进行如下动态生成:
其中a[i][0]代表在界面上所要显示的lebal中的内容,a[i][1]就是最大可输入的数字。
我需要i从0到i-1,依次遍历,这样就在界面上有好多行“lebal ------textbox”的东西了。 上面的a,就是相当于tcp,而当选mgcp的时候,相当于我又选了一个数组b[j][2];
注:其中所有的数组都是x[k][2]的结构,都是我从数据库读出来的,这里就当作已有的,随便定义几个就行。并且x[j][0]是字符串,用来显示lebal;x[j][1]是int型数字,就是textbox的最大输入而已。(0 <= j <= k-1) 这就是我的最终问题 我需要的应该是动态生成的吧,因为数组是我从数据库读出来的,k是不确定的,所以应该是动态生成的吧 真的麻烦了,就要答辩,所以急了些