Click here to Skip to main content
15,895,667 members
Articles / Programming Languages / C#

Add a 'Dont show this dialog again' Checkbox with minimal effort

Rate me:
Please Sign up or sign in to vote.
3.95/5 (16 votes)
9 Mar 2008CPOL4 min read 50.1K   381   48  
A control to let the user select to never see a dialog again.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Testapp
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			Form2 f2 = new Form2();
			DialogResult res = f2.ShowDialog();

			MessageBox.Show("Result: " + res);
		}

		private void button3_Click(object sender, EventArgs e)
		{
			Form2 f2 = new Form2();
			f2.Text = "Confirm another action";
			f2.label1.Text = "This text has been set after the original dialog has been created"
			+ "(bearing a different description).\n"
			+ "That way the same form class can be used in different configurations.";
			DialogResult res = f2.ShowDialog();

			MessageBox.Show("Result: " + res);
		}

		private void button2_Click(object sender, EventArgs e)
		{
			Form2 f2 = new Form2();
			MavControls.DontShowAgainCheckBox.Reset(f2);

			f2.Text = "Confirm another action";
			MavControls.DontShowAgainCheckBox.Reset(f2);

			MessageBox.Show("DontShowAgain flags have been reset. Both dialogs will show again.");
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) 4voice AG
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions