I adapted a roll-your-own Input box based on this.
I modified the code to the following:
using System;
using System.Windows.Forms;
public static class PromptForText
{
public static string ShowDialog(string caption, string text)
{
Form prompt = new Form();
prompt.Width = 280;
prompt.Height = 150;
prompt.Text = caption;
Label textLabel = new Label() { Left = 16, Top = 20, Width = 240, Text = text };
TextBox textBox = new TextBox() { Left = 16, Top = 40, Width = 240 };
Button confirmation = new Button() { Text = "Okie Doak", Left = 16, Width = 80, Top = 72 };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(textBox);
prompt.StartPosition = FormStartPosition.CenterScreen;
prompt.ShowDialog();
textBox.Focus();
return textBox.Text;
}
}
I added the "textBox.Focus()" but it doesn't do what I expected it to. I tried it both before and after the call to ShowDialog().
What am I missing? Why doesn't calling focus on the textbox set focus to same?
UPDATE
Controls being created now like so, based on Steve (Wozniak's?) answer:
TextBox textBox = new TextBox() { Left = 16, Top = 40, Width = 240, TabIndex = 0, TabStop = true };
Label textLabel = new Label() { Left = 16, Top = 20, Width = 240, Text = text };
Button confirmation = new Button() { Text = "Okie Doak", Left = 16, Width = 80, Top = 72, TabIndex = 1, TabStop = true };