c# - C# WinForms: Constructing an object with label/textbox properties in a form does not result in those properties appearing in the form. Why?
问题描述
What I'm doing is: I have an object which initializes its textbox/label contents in the constructor, however when the object is constructed in its intended form I can't make the contents appear on the form. An example:
public ProductEntry(int value){
this.productdesc = new TextBox
{
Location = new Point(x,y),
Width = 30,
Height = 30,
};
}
I tried adding visibility tags but that wasn't it. What am I doing wrong?
解决方案
您应该将此控件添加到表单中 - 如下所示:
YourForm.Controls.Add(productdesc);
这里有更详细的描述:https: //support.microsoft.com/pl-pl/help/319266/how-to-programmatically-add-controls-to-windows-forms-at-run-time-by -u
推荐阅读
- pandas - 在数据框中添加两列以形成列表
- firebase - 如何在颤振中只显示没有图像的文本
- javascript - 在页面加载时从模型向 FullCalendar 添加事件
- c++ - C++ 范围转换为 std::string 或在范围内搜索范围?
- odbc - Lotus Notes OLEDB/ODBC 连接失败与 SQL Server 2016
- json - 超出范围的浮点值不符合 Django 渲染的 JSON
- ansible - 自定义 Ansible 模块问题
- angular - Angular:如何使 Mat-Slide-Toggle 用作单选按钮?
- javascript - Puppeteer PDF 标题未显示在每一页上
- postgresql - postgres 12中带有前导零的隐蔽数字字符串到带有前导零的数值