[英]Cannot resize checkbox when dynamically adding checkboxes to form
In C#, I'm trying to dynamically add checkboxes to a tab sheet on a form. 在C#中,我试图将复选框动态添加到表单的选项卡中。 I've tried the AutoSize property but some of my text is too long. 我尝试了AutoSize属性,但是我的一些文本太长了。 the x.Size.Width
is returning: x.Size.Width
返回:
Cannot modify the return value of 'System.Windows.Froms.Control.Size' because it it not a variable 无法修改“ System.Windows.Froms.Control.Size”的返回值,因为它不是变量
I've searched through a lot of forums and can't seem to find an answer. 我搜索了很多论坛,但似乎找不到答案。 Any ideas? 有任何想法吗?
foreach (CheckBoxes i in main)
{
CheckBox x = new CheckBox();
x.Text = i.Data;
x.Checked = i.Condition;
x.Location = new Point(main_start_location_x, main_start_location_y);
x.Size.Width = 570;
tabControl1.TabPages["main_checklist_tab"].Controls.Add(x);
main_start_location_y += 40;
}
You must set the size of a control by using the control's Width
and Height
properties or the Size
property, but not the Width
and Height
of the Size
property, since that is passed by value and will have no effect. 您必须使用控件的设置控件的大小, Width
和Height
的属性或Size
属性,但不是Width
和Height
的的Size
属性,因为这是按值传递,将没有任何效果。
1) Control.Size = new Size(width, height);
1) Control.Size = new Size(width, height);
or 要么
2) Control.Width = width;
2) Control.Width = width;
instead of: 代替:
x.Size.Width = 570;
Use this: 用这个:
x.Width = 570;
if you want to set the whole size at once, do this: 如果要一次设置整个大小,请执行以下操作:
x.Size = new Size(570, 20);
or this: 或这个:
x.Width = 570;
x.Height = 20;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.