Include an if condition in message-box dialog code in c#
up vote
0
down vote
favorite
I have a message box dialog which comes with yes no like following. I have added no button as default selected button in the code. I want to do this by checking an if condition. Based on the if condition result I want to set the default button in the message dialog. I am doing it with "MessageBoxDefaultButton.Button2 "Without repeating message box dialog in an if the condition is there a way that I can set this button checking a value using an if condition inside this dialog box code.
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
}
c# winforms conditional messagebox messagedialog
add a comment |
up vote
0
down vote
favorite
I have a message box dialog which comes with yes no like following. I have added no button as default selected button in the code. I want to do this by checking an if condition. Based on the if condition result I want to set the default button in the message dialog. I am doing it with "MessageBoxDefaultButton.Button2 "Without repeating message box dialog in an if the condition is there a way that I can set this button checking a value using an if condition inside this dialog box code.
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
}
c# winforms conditional messagebox messagedialog
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a message box dialog which comes with yes no like following. I have added no button as default selected button in the code. I want to do this by checking an if condition. Based on the if condition result I want to set the default button in the message dialog. I am doing it with "MessageBoxDefaultButton.Button2 "Without repeating message box dialog in an if the condition is there a way that I can set this button checking a value using an if condition inside this dialog box code.
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
}
c# winforms conditional messagebox messagedialog
I have a message box dialog which comes with yes no like following. I have added no button as default selected button in the code. I want to do this by checking an if condition. Based on the if condition result I want to set the default button in the message dialog. I am doing it with "MessageBoxDefaultButton.Button2 "Without repeating message box dialog in an if the condition is there a way that I can set this button checking a value using an if condition inside this dialog box code.
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
}
c# winforms conditional messagebox messagedialog
c# winforms conditional messagebox messagedialog
edited Nov 7 at 11:18
Anas
497423
497423
asked Nov 7 at 11:09
CWW
62
62
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
I assume this is what you want.
bool myCondition = true;
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question,myCondition? MessageBoxDefaultButton.Button2:MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
}
add a comment |
up vote
0
down vote
Store your Default Button in a MessageBoxDefaultButton
:
MessageBoxDefaultButton DefaultButton = MessageBoxDefaultButton.Button1;
and use it:
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DefaultButton) == DialogResult.Yes)
{
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I assume this is what you want.
bool myCondition = true;
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question,myCondition? MessageBoxDefaultButton.Button2:MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
}
add a comment |
up vote
1
down vote
I assume this is what you want.
bool myCondition = true;
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question,myCondition? MessageBoxDefaultButton.Button2:MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
}
add a comment |
up vote
1
down vote
up vote
1
down vote
I assume this is what you want.
bool myCondition = true;
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question,myCondition? MessageBoxDefaultButton.Button2:MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
}
I assume this is what you want.
bool myCondition = true;
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question,myCondition? MessageBoxDefaultButton.Button2:MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
}
answered Nov 7 at 11:17
Nishil
2158
2158
add a comment |
add a comment |
up vote
0
down vote
Store your Default Button in a MessageBoxDefaultButton
:
MessageBoxDefaultButton DefaultButton = MessageBoxDefaultButton.Button1;
and use it:
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DefaultButton) == DialogResult.Yes)
{
}
add a comment |
up vote
0
down vote
Store your Default Button in a MessageBoxDefaultButton
:
MessageBoxDefaultButton DefaultButton = MessageBoxDefaultButton.Button1;
and use it:
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DefaultButton) == DialogResult.Yes)
{
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Store your Default Button in a MessageBoxDefaultButton
:
MessageBoxDefaultButton DefaultButton = MessageBoxDefaultButton.Button1;
and use it:
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DefaultButton) == DialogResult.Yes)
{
}
Store your Default Button in a MessageBoxDefaultButton
:
MessageBoxDefaultButton DefaultButton = MessageBoxDefaultButton.Button1;
and use it:
if (MessageBox.Show("Selected itemis already existing , Do you want to continue adding?", "XXX", MessageBoxButtons.YesNo, MessageBoxIcon.Question, DefaultButton) == DialogResult.Yes)
{
}
answered Nov 7 at 11:19
RezaNoei
591215
591215
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53188294%2finclude-an-if-condition-in-message-box-dialog-code-in-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown