TableLayoutPanel的用法? 关于TableLayoutPanel的用法,有几个问题请教:1.如果动态添加一行?2.如果删除一行?3.添加一行或删除时,如何不发生闪动?4.如果知道当前获取焦点是的哪一行?5.最后一行的空白如何处理? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/t/20061219/15/5241258.html这个贴子也无人结呀。 5.最后一行的空白如何处理?解决办法是控件自适应长度: 1〉添加一个Panel: AutoScroll为True2 〉添加一个TableLayoutPanel到Panel上面:AutoScroll为False、 AutoSize为True、 Dock为Top 1.如果动态添加一行?代码如下:tlpMastField.RowCount = tlpMastField.RowCount + 1;tlpMastField.RowStyles.Add(new RowStyle(System.Windows.Forms.SizeType.Absolute, 25f));int rowIndex = tlpMastField.RowCount - 1; //FieldName TextBox ttbxFieldName = new TextBox(); ttbxFieldName.Text = fieldName; //显示内容 ttbxFieldName.Name = "ttbxFd" + fieldName + rowIndex; //名称 ttbxFieldName.Multiline = true; //可显示多行 ttbxFieldName.BorderStyle = BorderStyle.Fixed3D; //边框类型 ttbxFieldName.BackColor = SystemColors.InactiveCaptionText; //背景颜色 ttbxFieldName.Dock = DockStyle.Fill; //完全占据父容器 ttbxFieldName.TextAlign = HorizontalAlignment.Left; //文本对齐方式 tlpMastField.Controls.Add(ttbxFieldName, 0, rowIndex); //添加到TableLayoutPanel 3.添加一行或删除时,如何不发生闪动? //避免闪动,布局先挂起 tlpMastField.SuspendLayout(); //添加行 ... ... //避免闪动,提交布局 tlpMastField.ResumeLayout(); 感觉没效果,待大牛解释... ... tlpMastField.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tlpDir, true, null); tlpMastField.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(tlpMastField, true, null);纠正一下. 自动布局 如何监视运行过程中各个变量的值 求目前最为通用公用的WinForm和WebForm控件命名规则 〓〓〓〓 急!! 如何给一个字节数组某些数组值赋值? 如何让treeview和listview的节点关联到对象 文件保存到数据库有大小限制吗? 如何取得一个函数的地址??? 哪位大侠知道一个通过编译自动给代码增加log的工具,进来拿分 未能找到类型或命名空间名称“CSharpWin"(是否缺少 using 指令或程序集引用?) TREEVIEW不能正常显示 C#如何获取JS生成的COOKIE RDLC报表 字体太紧凑
1〉添加一个Panel: AutoScroll为True
2 〉添加一个TableLayoutPanel到Panel上面:AutoScroll为False、 AutoSize为True、 Dock为Top
代码如下:
tlpMastField.RowCount = tlpMastField.RowCount + 1;
tlpMastField.RowStyles.Add(new RowStyle(System.Windows.Forms.SizeType.Absolute, 25f));int rowIndex = tlpMastField.RowCount - 1; //FieldName
TextBox ttbxFieldName = new TextBox();
ttbxFieldName.Text = fieldName; //显示内容
ttbxFieldName.Name = "ttbxFd" + fieldName + rowIndex; //名称
ttbxFieldName.Multiline = true; //可显示多行
ttbxFieldName.BorderStyle = BorderStyle.Fixed3D; //边框类型
ttbxFieldName.BackColor = SystemColors.InactiveCaptionText; //背景颜色
ttbxFieldName.Dock = DockStyle.Fill; //完全占据父容器
ttbxFieldName.TextAlign = HorizontalAlignment.Left; //文本对齐方式
tlpMastField.Controls.Add(ttbxFieldName, 0, rowIndex); //添加到TableLayoutPanel
//避免闪动,布局先挂起
tlpMastField.SuspendLayout(); //添加行
... ... //避免闪动,提交布局
tlpMastField.ResumeLayout(); 感觉没效果,待大牛解释... ...
纠正一下.