c#动态创建控件...

 

htmltable
tablerow
tablecell
动态创建Form
直接从标准控件中继承过来


动态创建Table
htmltable ht1=new htmltable();

动态创建tablerow,tablecell

tablerow tr = new tablerow
tablecell tc = new tablecell

在form中添加控件

form1.controls.add(table);

在htmltable中添加行htmltablerow

htmltable.rows.add(htmltablerow);

在htmltablerow中添加htmltablecell

htmltablerow.cells.add(htmltablecell);

在htmltable中添加其他控件

htmltable.controls.add(OtherControl)

设置属性

label.text="sadfsf"直接设置。。

设置背景颜色

htmltable.attributes["background"]="a.jpg";


       private void InitializeComponent()
        {
            Form1 = new HtmlForm();
            this.Controls.Add(Form1);
            Label lb1 = new Label();
            Label lb2 = new Label();
            tb1 = new TextBox();
            TextBox tb2 = new TextBox();
            Label lb3 = new Label();
            Label lb4 = new Label();
            ddl4 = new DropDownList();
            TableRow tr =new TableRow();
            DropDownList ddl1 = new DropDownList();
            Form1.Controls.Add(lb1);
            lb1.Text = "会员卡号";
            Form1.Controls.Add(tb1);
 
            lb2.Text = "姓名";
            Table table1 = new Table();
            Form1.Controls.Add(table1);
            table1.Rows.Add(tr);
            TableCell tabcl1 = new TableCell();
            tr.Cells.Add(tabcl1);
            tabcl1.Controls.Add(lb2);
            Form1.Controls.Add(tb2);
            table1.Rows.Add(tr);
            tr.Cells.Add(tabcl1);
            tabcl1.Controls.Add(ddl1);
            HtmlTable ht = new HtmlTable();
            Form1.Controls.Add(ht);
            ht.Border = 0;
            ht.CellPadding = 0;
            ht.CellSpacing = 0;
            ht.Height = "100";
            ht.Width = "100%";E
            ht.Attributes["background"]="a.jpg";
            HtmlTableRow htr = new HtmlTableRow();
            HtmlTableCell htc = new HtmlTableCell();
            ht.Rows.Add(htr);
            htr.BorderColor="red";
            htr.Height = "70";
            htr.Cells.Add(htc);
            htc.BorderColor="black";
            htc.Height="50";
            htc.Controls.Add(lb4);
            lb4.Text = "asdfsf";
            Form1.Controls.Add(ddl4);
            ddl4.Items.Add(new ListItem("男","M"));
            ddl4.Items.Add(new ListItem("女","F"));
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值