c# message box (make editable)

felkamau used Ask the Experts™
The code attached displays a short description as a message box. I would like to enhance this so that the user can edit the short description as they desire...any ideas on how I can get this accomplished?
private void lblShortDesc_Click(object sender, System.EventArgs e)
			//When the user clicks the short description, a messagebox shows the full text.
			MessageBox.Show(this, this.ShortDescription);

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016



I need to be able to edit the message in the textbox...you links are great but they are vague and do not address my issue
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

There is no built in way of doing what you are asking.  The only way to do it would be to create your own form.  


ajb222 - I'm now able to leverage your sample to my needs. One question: is there a way to make the size of the input box dynamic?
You could use Measurestring to set the width of the textbox

TextBox.Width = Me.CreateGraphics().MeasureString(promptText, TextBox.Font).Width

then set the width of the form based on textbox size

sorry that was in VB

here it is in C#

            textBox.Width = (int)this.CreateGraphics().MeasureString(promptText, textBox.Font).Width;


I made the text box a multiline and also made the form size static (see attached)...is there any way I can make the form size grow depending on the size of the text?
public  static DialogResult InputBox(string title, string promptText, ref string value)
			Form form = new Form();
			Label label = new Label();
			TextBox textBox = new TextBox();
			Button buttonOk = new Button();
			Button buttonCancel = new Button();

			form.Text = title;
			label.Text = promptText;
			textBox.Text = value;
			buttonOk.Text = "OK";
			buttonCancel.Text = "Cancel";
			buttonOk.DialogResult = DialogResult.OK;
			buttonCancel.DialogResult = DialogResult.Cancel;

			label.SetBounds(9, 20, 372, 13);
			textBox.SetBounds(12, 36, 372, 20);
			buttonOk.SetBounds(228, 72, 75, 23);
			buttonCancel.SetBounds(309, 72, 75, 23);

			label.AutoSize = true;
			textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
			buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
			buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

			form.ClientSize = new Size(396, 107);
			form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
			//form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
			//form.ClientSize = new Size(Math.Max(700, label.Right + 10), form.ClientSize.Height);
			form.ClientSize = new Size(Math.Max(700, label.Right + 10), 300);
			form.FormBorderStyle = FormBorderStyle.FixedDialog;
			form.StartPosition = FormStartPosition.CenterScreen;
			form.MinimizeBox = false;
			form.MaximizeBox = false;
			textBox.Multiline = true;
			form.AcceptButton = buttonOk;
			form.CancelButton = buttonCancel;

			textBox.Height = 150;
			DialogResult dialogResult = form.ShowDialog();
			value = textBox.Text;
			return dialogResult;

Open in new window

You still want to use MeasurString
 textBox.Width = (int)this.CreateGraphics().MeasureString(promptText, textBox.Font, maxwidth).Width;
 textBox.Height= (int)this.CreateGraphics().MeasureString(promptText, textBox.Font, maxwidth).Height;

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial