Reputation: 13616
Any idea how to display textBox control in MessageBox.
I'm working on winforms projcet c#.
Thank you in advance.
Upvotes: 19
Views: 96715
Reputation: 12805
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.
Upvotes: 24
Reputation: 1
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
Upvotes: 0
Reputation: 69
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 !
Upvotes: -1
Reputation: 487
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.
Upvotes: 18
Reputation: 2812
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.
Upvotes: 0
Reputation: 3256
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();
Upvotes: 2
Reputation: 1728
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.
Upvotes: 4
Reputation: 14874
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.
Upvotes: 1
Reputation: 26737
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
Upvotes: 2