简体   繁体   中英

how to display textBox control in MessageBox?

Any idea how to display textBox control in MessageBox.

I'm working on winforms projcet c#.

Thank you in advance.

You can't. MessageBox is a special container designed to only show a message and buttons. Instead, you can create your own Form with whatever controls you want, and use .ShowDialog() on it.

You can simply add an Input box from VB.NET into your C# project. First add Microsoft.VisualBasic to your project References, then use the following code:

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

more info at

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.

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.

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.

Yes, as krillgar mentioned,you should create your own form. And 1. Encapsulate the form in a static class or function, so you may just call 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.

Regarding to item 2, I believe many Windows build applications and MS Office use such approach.

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.

Remember to add the reference "Microsoft.VisualBasic" in the solution explorer

Solution in here, you can create windows form and design it, set form is dialog, when you call form, it is auto show. 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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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