[英]is it possible to add elements like panel to a listbox, listview or other list with .items value using c# and winforms?
is it possible to add elements like panel to a listbox, listview or other list with.items?是否可以将面板等元素添加到列表框、列表视图或其他带有.items 的列表?
I want to create panels with other elements like labels, checkbox, buttons,.. on a panel.我想在面板上创建带有标签、复选框、按钮等其他元素的面板。 The panel should then be in a list so that I can check it for example: checkbox (which is on the panel) and is active in the list is showing, the other elements should be hidden in the list.
然后面板应该在一个列表中,以便我可以检查它,例如:复选框(在面板上)并且在列表中处于活动状态正在显示,其他元素应该隐藏在列表中。 If a panel is between 2 panels, it should move upwards so that there is no space in between.
如果一个面板位于两个面板之间,它应该向上移动,这样中间就没有空间了。 If I then only display the panels of the non-activated elements, the hidden ones should be displayed again and the displayed ones should be hidden.
如果我只显示未激活元素的面板,则应再次显示隐藏的面板,并隐藏显示的面板。
I would like to control this display using button event,我想使用按钮事件来控制这个显示,
With another button I would like to be able to bring a panel to the top position if it was declared as a favorite.如果它被宣布为收藏夹,我希望能够使用另一个按钮将面板带到顶部 position。 if the favorite is removed again it should go back to where it was before.
如果收藏夹再次被删除,它应该 go 回到原来的位置。
In addition, I would then like to create a search mask that only displays the elements that match the search string when entered.此外,我想创建一个搜索掩码,仅在输入时显示与搜索字符串匹配的元素。
The only way I found is with listbox1.Controls.Add(panel1);我发现的唯一方法是使用 listbox1.Controls.Add(panel1); for it to appear.
让它出现。 Unfortunately it doesn't work with listbox1.Items.
不幸的是,它不适用于 listbox1.Items。 :( So I don't have a selectedItem either....
:( 所以我也没有 selectedItem ......
Here is my code that I have so far:这是我到目前为止的代码:
private void Reload_Click(object sender, EventArgs e)
{
Panel panel1 = new Panel();
panel1.Size = new Size (250, 35);
panel1.BackColor = Color.Red;
panel1.ForeColor = Color.Green;
panelxy.Dock = DockStyle.Top;
Panel panel2 = new Panel();
panel2.Size = new Size(250, 35);
panel2.BackColor = Color.Blue;
panel2.ForeColor = Color.Green;
panel2.Dock = DockStyle.Top;
listBox1.Controls.Add(panel1);
listBox1.Controls.Add(panel2);
Button btn_1 = new Button();
btn_1 .Size = new Size(200, 30);
btn_1 .Location = new Point(5, 2);
btn_1 .ForeColor = Color.Blue;
btn_1 .BackColor = Color.Yellow;
btn_1 .Font = new Font("Sitka Text", 15F, (FontStyle)(FontStyle.Bold | FontStyle.Italic), GraphicsUnit.Point, (byte) 0);
btn_1 .Text = "testbutton";
panel1.Controls.Add(btn_1 );
}
And here a Picture to show that:这里有一张图片来显示:
I hope someone can help me here.我希望有人可以在这里帮助我。 :) thanks and BR
:) 谢谢和BR
Cusy粗鲁的
Super thank you!超级感谢!
I just found out that it is possible to realize the required with a TableLayoutPanel.我刚刚发现可以使用 TableLayoutPanel 实现所需。 :)
:)
Since I already have about 7000 lines of code, I don't want to convert it to WPF.由于我已经有大约 7000 行代码,我不想将其转换为 WPF。 ;) i think the Answer from "Jimi" with FlowLayoutPanel are also a Solution.
;) 我认为来自“Jimi”和 FlowLayoutPanel 的答案也是一个解决方案。 :) Thanks
:) 谢谢
BR Cusy BR 库西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.