c# - 如何将面板添加到另一个面板
问题描述
当我单击 button1 时,我想将其中一个panel1,2,... 添加到 panel0 中。
这是我的代码
private void button3_Click(object sender, EventArgs e)
{
int i = 0;
int j = 0;
Panel[] pnl = new Panel[3];
while ( i<2)
{
pnl[i].Parent = panel0; // erorr
pnl[i].BackColor = Color.PeachPuff;
pnl[i].Size = new Size(50, 10);
pnl[i].Location = new Point(j+5,10);
panel0.Controls.Add(pnl[i]);
pnl[i].BringToFront();
i++;
j = j + 13;
}
}
有建议吗?
解决方案
将 Panel[] pnl = new Panel[3] 更改为:
var pnl = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};
推荐阅读
- python - 获取异常类型+消息作为字符串中的except
- javascript - JavaScript 从数组构建数组
- javascript - 未捕获(承诺中)FirebaseError:调用者在firestore中没有权限
- javascript - 每次在 Node.js (Express.js) 中发出 API 请求之前,如何简化 Fetching Auth token?
- svg - 具有透明背景的 SVG 蒙版线动画
- python - Python 与 Java 字节码
- node.js - 如何将图像存储在文件服务器中并获取远程 URL 以响应本机应用程序
- c# - 如何动态处理列表使用反射并将返回的数据转换为列表
- reactjs - React.JS TypeError:无法读取未定义的属性“编号”-(在 setState 内)
- php - 工匠路线:列表不适用于 laravel 中的身份验证