• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Help with placing focus on button in message box


I am using the code below  for users to decide Yes/No, is there a way to place the focus on No automatically and they would only need to press Enter or Click on it? Below is the code I am using.

Dim anadd As String
                    anadd = MsgBox("Are you sure you want to Add this record?", MsgBoxStyle.YesNo, "Warning before Attempting Adding record")
                    If anadd = MsgBoxResult.Yes Then
                     code is executed.....

I am using ASP.NET


  • 3
1 Solution
I believe you are looking for MsgBoxDefaultButton. Then you have to play around with which button it might be. Should be button 2 though.

Here is an example:

MsgBox.Show(messageString, "Do you want to quit?", MsgBoxButtons.YesNo, MsgBoxIcon.Question, MsgBoxDefaultButton.Button2) 

Open in new window

You will have to use Messagebox.Show as I believe msgbox does not accept this parameter
Oops, CodeCruiser is right. I was getting the two mixed up. The link below should explain every clearly.

MessageBoxDefaultButton Enumeration

In my rush to answer the question,  I forgot that MsgBox and Messagebox.Show() are essentially the same thing, except that Messagebox.Show() allows for far more customization though.

Thank you for clarifying that CodeCruiser.
vcharlesAuthor Commented:
Thank You!
My pleasure. Thanks for asking!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now