I would like to create a message box which has a textbox to enter a string in it how is this possible?

Sure it is. What you have to so, is to create a new Form, that will look like a messageBox. Put a textBox on it, and a buttons (Ok, Cancel, or what ever).
Simple.

Add a reference to Microsoft.VisualBasic and you can do:

string response = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "DefaultResponse",5,5);

While this gets the job done, I'd recommend making a form like Mitja Bonca suggested, as it's pure C# and infinitely more customizable.

string response = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "DefaultResponse",5,5);
is the best! It is harder to create another form, etc.
Remember to reference Microsoft.VisualBasic

Mitja is right in C# we have to create a new form to take input as a messagebox the is no implicit way to do that ....

String Response=MessageBox.Show("checking", "check", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question).ToString()
//to check any specific response 
if(MessageBox.Show("checking", "check", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)==DialogResult.Yes)

Edited 5 Years Ago by abelLazm: n/a

I decided to create a new form as it is easier for me and less complicated.. now how can i pass the input from the Messagebox to the opened form?

Edited 5 Years Ago by xanawa: n/a

Write a function in main form and before closing the child form call this function.

//code in main form
string value1="";
public void SetValue1(String val)
{
value1=val;
}


//code in child form
//rest of the code.
mainForm obj= new mainForm();
obj.SetValue1(textBox12.text);
//obj.Show();
//rest of the code

Edited 5 Years Ago by abelLazm: n/a

Write a function in main form and before closing the child form call this function.

//code in main form
string value1="";
public void SetValue1(String val)
{
value1=val;
}


//code in child form
//rest of the code.
mainForm obj= new mainForm();
obj.SetValue1(textBox12.text);
//obj.Show();
//rest of the code

i am throwing the value into a label and it is 0.. i am really freaking out atm.. whaty shoudl i do pls?

Make Panel as messagebox and when you make it visible make all other controls' enable status = false; and when you finish taking input make the panel invisible and all other controls enabled =true.... it will solve your passing value problem

Hello, so you have decided to do as I told you. Its sure the best idea (simple and fast).
You can use a ShowDialog method:

//form1:
     public partial class Form1 : Form
    {
        public static string Form2_Message { get; set; }
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
        }

        private void buttonMessage_Click(object sender, EventArgs e)
        {
            using (Form2 f2 = new Form2())
            {
                if (f2.ShowDialog() == DialogResult.OK)
                {
                    label1.Text = Form2_Message;
                }
                else
                    label1.Text = "";
            }
        }
    }

//form2 - MessageBox:
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.Text = "My messageBox";
            label1.Text = "";
        }

        private void buttoConfirm_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != String.Empty)
            {
                Form1.Form2_Message = textBox1.Text;
                this.DialogResult = DialogResult.OK;
            }
            else
                label1.Text = "Please write some message...";
        }

        private void buttonDecline_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
This article has been dead for over six months. Start a new discussion instead.