[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Set the MessageBox default button in C#

[Set the MessageBox default button in C#]

The fifth parameter to MessageBox.Show indicates the default button. The following code shows how the program displays a MessageBox with the second button as the default so it is initially selected when the message box appears.

// Display a message box with the second button the default. private void btnButton2_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show( "The second button is the default.", "Caption", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); MessageBox.Show("You selected " + result.ToString()); }

That's all there is to it. It's not very complicated, it's just not well known.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.