简体   繁体   English

单击按钮如何使列表框显示在表单上?

[英]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.aspxhttps://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.

相关问题 如何使用双击事件单击列表框中的文本以使该文本显示在空文本框中 - How to use a double click event to click text in a listbox to make that text appear in a empty textbox C#Windows窗体应用程序-如何在单击按钮时获取单选按钮以提示文本出现在列表框中? - C# Windows Form Application - How to get Radio Button to prompt text to appear in a Listbox upon clicking a Button? 如何使表单在加载时单击按钮? - How to make a form click a button when loaded? 单击按钮以使文本出现在另一个表单文本框中 - Click button for a text to appear in a another form textbox 如何通过单击按钮将列表框数据从form1传递到form2 - How to pass listbox data from form1 to form2 with a button click 如何使按钮显示为按下? - How to make a button appear as if it is pressed? 如何单击IsHitTestVisible为false的列表框中的按钮? - how to click a button in listbox that IsHitTestVisible is false? 如何在单击按钮时使用另一个列表框在列表框中插入项目 - How to insert items inside listbox withing another listbox on button click 如何使单击按钮以其他形式更改标签文本? - How to make click button to change label text in other form? 如何通过单击按钮使表单标题动态更改? - How do you make a form title dynamically change with a button click?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM