I have a very simple error popup I’m trying to make. When I call ShowDialog, all the text in the textbox gets selected. It looks silly. When I break right before ShowDialog, no text is selected. After the call to ShowDialog, all the text is selected without any user interaction.
static void ShowError(string error)
{
var form = new Form
{
Text = "Unexpected Error",
Size = new System.Drawing.Size(800, 600),
StartPosition = FormStartPosition.CenterParent,
ShowIcon = false,
MinimizeBox = false,
MaximizeBox = false
};
var textBox = new TextBox
{
Text = error,
Dock = DockStyle.Fill,
Multiline = true,
ReadOnly = true,
};
form.Controls.Add(textBox);
form.ShowDialog();
}
You can add
SelectionStart=0, SelectionLength = 0orEnabled = falseto your textBox creation code