简体   繁体   English

如何使文本框仅在用户单击C#中的按钮后出现

[英]How to make textbox appear only after user clicks button in c#

How would I make a textbox appear only after clicking a button. 我如何使文本框仅在单击按钮后出现。 THis means that It should be hidden, and once user clicks, then it can appear. 这意味着它应该被隐藏,并且一旦用户单击,它就会出现。

 private void button7_Click(object sender, EventArgs e)
 {
        // .. what next?      
 }

You can use Control.Visible to make any control visible or hidden: 您可以使用Control.Visible使任何控件可见或隐藏:

private void button7_Click(object sender, EventArgs e)
{
    theTextBox.Visible = true;
}

Just set it's Visible property to false initially (ie: in the designer). 最初只需将其Visible属性设置为false (即:在设计器中)。

Assuming you have defined a TextBox textBox1 somewhere: 假设您在某处定义了TextBox textBox1

private void button7_Click(object sender, EventArgs e)
{
    textBox1.Visible = !textBox1.Visible;      
}

This way you can toggle the visibility. 这样,您可以切换可见性。

You can set it just to true if you like, but make sure the initial Visible state, you can set it in the designer, is false . 您可以根据需要将其设置为true ,但是请确保可以在设计器中将其设置为Visible的初始状态为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使C#按钮仅单击一次并使文本框显示两个结果? - How to make C# button click only one time and make a textbox show two result? 只有当鼠标在asp.net C中的div上时,如何制作标签和按钮# - how to make labels and button appear only when mouse is over a div in asp.net C# C#如何通过单击其他按钮使另一个按钮出现? - C# How to make another button appear by clicking a different button? 如何制作一个可以限制用户的文本框只能将输入从 0000 写入 FFFF。 c# - How to make a textbox that can limit the user can only write the input from 0000 to FFFF only. c# 如何在Microsoft Visual C#中5秒后显示图片? - How to make a picture appear after 5 seconds in Microsoft Visual C#? 如何在用户点击注销按钮后让用户登录系统并注销? - How to keep user login in to system and logout only after user clicks on logout button? 如何使文本框只接受出生日期格式 c# - how to make a textbox accept only date of birth format c# C#:当用户单击按钮时如何查看图像? - C#: How do I view an image when a user clicks on a button? 用户单击浏览器停止按钮时如何停止服务器端处理(ASP.net C#) - How to stop server side processing when user clicks browser stop button (ASP.net C#) 当用户单击不正确的按钮时,如何使c#应用程序弹出视频? - How do I get my c# application to popup a video when user clicks incorrect button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM