简体   繁体   English

如何在 MessageBox 中显示 textBox 控件?

[英]how to display textBox control in MessageBox?

Any idea how to display textBox control in MessageBox.知道如何在 MessageBox 中显示 textBox 控件。

I'm working on winforms projcet c#.我正在研究 winforms projcet c#。

Thank you in advance.先感谢您。

You can't.你不能。 MessageBox is a special container designed to only show a message and buttons. MessageBox 是一个特殊的容器,旨在仅显示消息和按钮。 Instead, you can create your own Form with whatever controls you want, and use .ShowDialog() on it.相反,您可以使用您想要的任何控件创建自己的表单,并在其上使用.ShowDialog()

You can simply add an Input box from VB.NET into your C# project.您可以简单地从 VB.NET 添加一个输入框到您的 C# 项目中。 First add Microsoft.VisualBasic to your project References, then use the following code:首先将Microsoft.VisualBasic添加到您的项目引用中,然后使用以下代码:

string UserAnswer = Microsoft.VisualBasic.Interaction.InputBox("Your Message ", "Title", "Default Response");

And that should work properly.这应该可以正常工作。

It will be better to add a new Form in you application which you can customize the way you want.最好在您的应用程序中添加一个新表单,您可以按照自己的方式自定义。

and just call it from where ever required.只需从需要的地方调用它。

you could create a classic win form that looks like a message box and opening it as a modal form perhaps using Form.ShowDialog您可以创建一个看起来像消息框的经典 win 表单,并将其作为模态表单打开,也许使用Form.ShowDialog

more info at更多信息在

http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx

You cannot customise the MessageBox, its better you use a popup designed using Windows Form separately and use its instance to invoke.您无法自定义 MessageBox,最好使用单独使用 Windows 窗体设计的弹出窗口并使用其实例进行调用。

customPopup popup = new customPopup();
popup.ShowDialog();

Place your controls on the popup form and set their access modifiers to public if you want to access the textboxes or labels etc in your previous form.如果您想访问之前表单中的文本框或标签等,请将您的控件放在弹出表单上并将它们的访问修饰符设置为 public。

customPopup popup = new customPopup();
popup.msgLabel.Text= "Your message";
popup.ShowDialog();

As I know there is no way to do that.据我所知,没有办法做到这一点。

You can create a winform change it's style to look like a MessageBox and add your own controls.您可以创建一个 winform,将其样式更改为 MessageBox 并添加您自己的控件。

Yes, as krillgar mentioned,you should create your own form.是的,正如 krillgar 所提到的,您应该创建自己的表单。 And 1. Encapsulate the form in a static class or function, so you may just call MyMessageBox.Show().并且 1. 将表单封装在静态类或函数中,因此您可以调用 MyMessageBox.Show()。 2. The textbox should have readonly=true, so the end users won't be able to change the text displayed, while they could select text and copy to clipboard. 2. textbox 应该有 readonly=true,所以最终用户将无法更改显示的文本,而他们可以选择文本并复制到剪贴板。

Regarding to item 2, I believe many Windows build applications and MS Office use such approach.关于第 2 条,我相信许多 Windows 构建应用程序和 MS Office 都使用这种方法。

using Microsoft.VisualBasic;//add reference
var Password = Interaction.InputBox("Message", "Title" ,"information in textbox", -1,-1);

In the variable "password" it receives the information that is entered from the text box.在变量“password”中,它接收从文本框中输入的信息。

Remember to add the reference "Microsoft.VisualBasic" in the solution explorer请记住在解决方案资源管理器中添加引用“Microsoft.VisualBasic”

Solution in here, you can create windows form and design it, set form is dialog, when you call form, it is auto show.解决方案在这里,你可以创建windows窗体并设计它,设置窗体是对话框,当你调用窗体时,它是自动显示。 In form you design, you set value some parameter static where other class in project, but you should set when you close form design that, OK, come back form init call show dialog, you create interval call when have == null return call, when != null you stop call back and using parameter in class static it !在你设计的表单中,你在项目中的其他类中设置了一些参数静态的值,但是你应该在关闭表单设计时设置,好的,返回表单初始化调用显示对话框,当有==空返回调用时创建间隔调用,当 != null 时,您将停止回调并在类 static 中使用参数!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM