मैं कैसे कहूंगा कि संदेशबॉक्स पर हाँ बटन दबाया गया था, वह और दूसरा? सी # में।संदेशबॉक्स बटन?
23
A
उत्तर
55
MessageBox.Show
आवश्यकताओं के आपका कॉलMessageBoxButtons.YesNo
पारित करने के लिए हाँ/नहीं बजाय बटन ठीक बटन मिलता है।DialogResult.Yes
करने के लिए कि कॉल (जो संवाद रिटर्न जब तक निष्पादन को अवरुद्ध कर देगा) का परिणाम की तुलना करें ....
if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
// user clicked yes
}
else
{
// user clicked no
}
6
if(DialogResult.OK==MessageBox.Show("Do you Agree with me???"))
{
//do stuff if yess
}
else
{
//do stuff if No
}
8
आप वास्तव में हाँ और कोई बटन चाहते हैं (यह मानते हुए WinForms):
void button_Click(object sender, EventArgs e)
{
var message = "Yes or No?";
var title = "Hey!";
var result = MessageBox.Show(
message, // the message to show
title, // the title for the dialog box
MessageBoxButtons.YesNo, // show two buttons: Yes and No
MessageBoxIcon.Question); // show a question mark icon
// the following can be handled as if/else statements as well
switch (result)
{
case DialogResult.Yes: // Yes button pressed
MessageBox.Show("You pressed Yes!");
break;
case DialogResult.No: // No button pressed
MessageBox.Show("You pressed No!");
break;
default: // Neither Yes nor No pressed (just in case)
MessageBox.Show("What did you press?");
break;
}
}
0
चेक करें:
+०१२३५१६४१०६ if (
MessageBox.Show(@"Are you Alright?", @"My Message Box",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//YES ---> Ok IM ALRIGHHT
}
else
{
//NO --->NO IM STUCK
}
सादर
2
.NET 4.5 के लिए सही जवाब का एक अद्यतन संस्करण होगा।
if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxImage.Question)
== MessageBoxResult.Yes)
{
// If yes
}
else
{
// If no
}
इसके अतिरिक्त, यदि आप दृश्य मॉडल में कमांड पर बटन को बांधना चाहते हैं तो आप निम्न का उपयोग कर सकते हैं। जबकि MessageBox विंडो में 'हां' या 'नहीं' बटन दबाने की स्थिति की जांच करने के लिए इस तरह
public RelayCommand ShowPopUpCommand
{
get
{
return _showPopUpCommand ??
(_showPopUpCommand = new RelayCommand(
() =>
{
// Put if statement here
}
}));
}
}
0
: यह MvvmLite साथ संगत है।
DialogResult d = MessageBox.Show("Are you sure ?", "Remove Panel", MessageBoxButtons.YesNo);
if (d == DialogResult.Yes)
{
//Contents
}
else if (d == DialogResult.No)
{
//Contents
}
@xxMUROxx कृपया रिफैक्टर कोड के उत्तर संपादित न करें। यदि आपको सुधार के साथ अतिरिक्त सामग्री जोड़ने की आवश्यकता महसूस होती है, तो कोई टिप्पणी छोड़ दें या अपना उत्तर जोड़ें। –