[英]How to make a listbox appear on the form at the click of a button?
I'm a university student therefore I'm not sure on everything to do with writing code. 我是一名大学生,因此我不确定与编写代码有关的所有事情。 If you could provide hints or a bit of help. 如果您可以提供提示或帮助。 I have hidden the listbox via the designer. 我已经通过设计师隐藏了列表框。 I've tried listbox1.Show under next button event handler. 我已经尝试过下一个按钮事件处理程序下的listbox1.Show。 I've tried looking around on the web but I'm getting no where. 我曾尝试在网上四处寻找,但是却一无所获。
Now answered. 现在回答。 Thank you 谢谢
The solution depends on how you've hidden your listbox. 解决方案取决于您如何隐藏列表框。 If you did set visible property to false, just use listbox1.Visible = true;
如果确实将visible属性设置为false,则只需使用listbox1.Visible = true;
. 。 If you used ' Send to back' to hide it behind another control, you can use listbox1.BringToFront();
如果使用“发送回”将其隐藏在另一个控件的后面,则可以使用listbox1.BringToFront();
to set it into the foreground. 将其设置为前台。
See https://msdn.microsoft.com/en-gb/library/system.windows.forms.control.visible.aspx and https://msdn.microsoft.com/en-gb/library/system.windows.forms.control.bringtofront.aspx 请参阅https://msdn.microsoft.com/en-gb/library/system.windows.forms.control.visible.aspx和https://msdn.microsoft.com/en-gb/library/system.windows.forms .control.bringtofront.aspx
在Button_Click事件内部写入:listbox1.Visible = true;
In my opinion, the best way to show/hide controls (in WPF) is to collapse them. 我认为,显示/隐藏控件(在WPF中)的最佳方法是折叠它们。 This allows the rest of the controls to behave as if the collapsed control does not even exists, until it is made visible, of course. 当然,这使其余控件的行为就像折叠的控件甚至不存在一样,直到它变为可见为止。
This would be done like so: 可以这样进行:
control1.Visibility = Visibility.Collapsed;
control1.Visibility = Visibility.Visible;
If you are using WinForms, controls will not have a collapse option, and the correct way would be as Almansour has said. 如果您使用的是WinForms,则控件将没有折叠选项,正确的方法将如Almansour所说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.