c#动态添加控件
来源:互联网 发布:mac英文字体打包下载 编辑:程序博客网 时间:2024/06/11 08:52
private void button1_Click(object sender, EventArgs e)
{
//tabJianCha
//新建TableLayoutPanel(tab)
TableLayoutPanel tab = new TableLayoutPanel();
tab.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tab.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
tab.ColumnCount = 5;
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[0].SizeType, tableLayoutPanel7.ColumnStyles[0].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[1].SizeType, tableLayoutPanel7.ColumnStyles[1].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[2].SizeType, tableLayoutPanel7.ColumnStyles[2].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[3].SizeType, tableLayoutPanel7.ColumnStyles[3].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[4].SizeType, tableLayoutPanel7.ColumnStyles[4].Width));
tab.Left = tableLayoutPanel7.Left;
tab.Top = tableLayoutPanel7.Top + tableLayoutPanel7.Height * (panel5.Controls.Count);
tab.Margin = Padding.Empty;
tab.RowCount = 1;
tab.RowStyles.Add(new RowStyle(tableLayoutPanel7.RowStyles[0].SizeType, tableLayoutPanel7.RowStyles[0].Height));
tab.Size = tableLayoutPanel7.Size;
tab.TabIndex = tableLayoutPanel7.TabIndex;
//新建"项目名称"下拉选择框
ComboBox cb = new ComboBox();
cb.Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
//cb.DropDownAutoSuitWidth = false;
cb.Location = txtJiaoFeiFangShi.Location;
cb.Items.AddRange(new object[] {
"刷卡",
"现金",
"银行"});
cb.Size = txtJiaoFeiFangShi.Size;
cb.Text = "现金";
tab.Controls.Add(cb, 0, 0);
TextBox[] txt = new TextBox[3];
//新建银行
txt[0] = new TextBox();
txt[0].Location = new Point(txtYinHang.Left, txtYinHang.Top);
txt[0].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[0].Size = new Size(txtYinHang.Width, txtYinHang.Height);
txt[0].TabIndex = txtYinHang.TabIndex;
tab.Controls.Add(txt[0], 1, 0);
//新建卡号
txt[1] = new TextBox();
txt[1].Location = new Point(txtKaHao.Left, txtKaHao.Top);
txt[1].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[1].Size = new Size(txtKaHao.Width, txtKaHao.Height);
txt[1].TabIndex = txtKaHao.TabIndex;
tab.Controls.Add(txt[1], 2, 0);
//新建金额
txt[2] = new TextBox();
txt[2].Location = new Point(txtJinE.Left, txtJinE.Top);
txt[2].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[2].Size = new Size(txtJinE.Width, txtJinE.Height);
txt[2].TabIndex = txtJinE.TabIndex;
tab.Controls.Add(txt[2], 3, 0);
//新建删除按钮
Button button = new Button();
button.Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
button.Location = new Point(btnAdd.Left, btnAdd.Top);
button.Size = new Size(btnAdd.Width, btnAdd.Height);
button.TabIndex = btnAdd.TabIndex;
button.Text = "删除";
button.UseVisualStyleBackColor = true;
tab.Controls.Add(button, 4, 0);
button.Click += delegate(object sender3, EventArgs e3)
{
button.Parent.Dispose();
int top = panel5.Controls[0].Top;
for (int i = 0; i < panel5.Controls.Count; i++)
{
panel5.Controls[i].Top = tableLayoutPanel7.Height * i + top;//删除中间一行之后将下方的上移
}
};
panel5.Controls.Add(tab);//把tab添加到panel5
}
{
//tabJianCha
//新建TableLayoutPanel(tab)
TableLayoutPanel tab = new TableLayoutPanel();
tab.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
tab.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
tab.ColumnCount = 5;
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[0].SizeType, tableLayoutPanel7.ColumnStyles[0].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[1].SizeType, tableLayoutPanel7.ColumnStyles[1].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[2].SizeType, tableLayoutPanel7.ColumnStyles[2].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[3].SizeType, tableLayoutPanel7.ColumnStyles[3].Width));
tab.ColumnStyles.Add(new ColumnStyle(tableLayoutPanel7.ColumnStyles[4].SizeType, tableLayoutPanel7.ColumnStyles[4].Width));
tab.Left = tableLayoutPanel7.Left;
tab.Top = tableLayoutPanel7.Top + tableLayoutPanel7.Height * (panel5.Controls.Count);
tab.Margin = Padding.Empty;
tab.RowCount = 1;
tab.RowStyles.Add(new RowStyle(tableLayoutPanel7.RowStyles[0].SizeType, tableLayoutPanel7.RowStyles[0].Height));
tab.Size = tableLayoutPanel7.Size;
tab.TabIndex = tableLayoutPanel7.TabIndex;
//新建"项目名称"下拉选择框
ComboBox cb = new ComboBox();
cb.Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
//cb.DropDownAutoSuitWidth = false;
cb.Location = txtJiaoFeiFangShi.Location;
cb.Items.AddRange(new object[] {
"刷卡",
"现金",
"银行"});
cb.Size = txtJiaoFeiFangShi.Size;
cb.Text = "现金";
tab.Controls.Add(cb, 0, 0);
TextBox[] txt = new TextBox[3];
//新建银行
txt[0] = new TextBox();
txt[0].Location = new Point(txtYinHang.Left, txtYinHang.Top);
txt[0].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[0].Size = new Size(txtYinHang.Width, txtYinHang.Height);
txt[0].TabIndex = txtYinHang.TabIndex;
tab.Controls.Add(txt[0], 1, 0);
//新建卡号
txt[1] = new TextBox();
txt[1].Location = new Point(txtKaHao.Left, txtKaHao.Top);
txt[1].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[1].Size = new Size(txtKaHao.Width, txtKaHao.Height);
txt[1].TabIndex = txtKaHao.TabIndex;
tab.Controls.Add(txt[1], 2, 0);
//新建金额
txt[2] = new TextBox();
txt[2].Location = new Point(txtJinE.Left, txtJinE.Top);
txt[2].Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
txt[2].Size = new Size(txtJinE.Width, txtJinE.Height);
txt[2].TabIndex = txtJinE.TabIndex;
tab.Controls.Add(txt[2], 3, 0);
//新建删除按钮
Button button = new Button();
button.Anchor = ((AnchorStyles)((AnchorStyles.Left | AnchorStyles.Right)));
button.Location = new Point(btnAdd.Left, btnAdd.Top);
button.Size = new Size(btnAdd.Width, btnAdd.Height);
button.TabIndex = btnAdd.TabIndex;
button.Text = "删除";
button.UseVisualStyleBackColor = true;
tab.Controls.Add(button, 4, 0);
button.Click += delegate(object sender3, EventArgs e3)
{
button.Parent.Dispose();
int top = panel5.Controls[0].Top;
for (int i = 0; i < panel5.Controls.Count; i++)
{
panel5.Controls[i].Top = tableLayoutPanel7.Height * i + top;//删除中间一行之后将下方的上移
}
};
panel5.Controls.Add(tab);//把tab添加到panel5
}
- c#动态添加控件
- C# 动态添加控件
- C# WinForm 动态添加控件
- C#动态添加label控件
- C# winform 动态添加控件
- C# 动态添加控件的方法
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行 .
- C# DataGridView控件 动态添加新行
- C# DataGridView控件 动态添加新行
- C#实现动态添加和删除控件
- C# DataGridView控件 动态添加新行
- C#给控件动态添加事件
- C# DataGridView控件 动态添加新行
- 在C#中动态地添加控件
- C# DataGridView控件动态添加新行
- C# 动态添加与删除控件
- 百度面试题:从输入url到显示网页,后台发生了什么?
- Google面试题及答案
- 生产者和消费者实现(Java)
- 第十一周项目3 求阿姆斯特朗数
- 【ACM】杭电1544:Palindromes
- c#动态添加控件
- heartbeat自带的断网切换功能-ipfai
- C#判断字符串是否为数字5种方案
- Chrome中利用HTML5实现具有文件“编辑”及“下载”功能的本地应用
- visio 画 弯曲 箭头 ( 波浪线 曲线)
- min2440LCD驱动
- Day09第九天java基础------------内部类
- gcc选项参数-M
- Day10第十天java基础---------异常