MessageBox.
Show("Do you want to save","Caption",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);YesNoCancel Button
How should i add the functionality of this YesNoCancel button.
MessageBox.
Show("Do you want to save","Caption",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 18, 2011, 2:46 AM EST
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result;
result = MessageBox.Show("Are you sure you want to exit?", "Application 1", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.No)
{
MessageBox.Show("App won´t close");
}
if (result == DialogResult.Yes)
{
this.Dispose();
}
}
}
}
Thanks
Datta KharadRank #2,135 · 668 reputationPosted Nov 18, 2011, 2:43 AM EST
DialogResult result= MessageBox.Show("Do you want to save...!!!", "Caption", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
switch (result)
{
case DialogResult.Yes:
{
this.Text = "Here your Save operation";
break;
}
case DialogResult.No:
{
this.Text = "Here your Without saving";
break;
}
case DialogResult.Cancel:
{
this.Text = "Here your do nothing operation";
break;
}
}
Gomathi PalaniswamyRank #714 · 3.3K reputationPosted Nov 18, 2011, 2:45 AM EST
{
MessageBox.Show("Yes");
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 18, 2011, 2:50 AM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
switch (MessageBox.Show("Do you want to create a new file?", "YesNoCancel", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{
case DialogResult.Yes:
// "Yes" processing
break;
case DialogResult.No:
// "No" processing
break;
case DialogResult.Cancel:
// "Cancel" processing
break;
}
}
}
}