RDR
RDR

Reputation: 1143

Create a message box that user can choose to "Don't show it again."

Made a mass messenger & a multi-message/spammer in one, works fine, just want to make it even better. Obviously I had to write code to have skype allow the program so it can do what it does, here it is,

    private void Form1_Load(object sender, EventArgs e)
    {
        //I entered a message box so it doesn't crash instantly.
        MessageBox.Show("Please allow SkypeBot.vshost.exe to access skype. (Look at your Skype application)");
        Skype skype = new Skype();
        skype.Attach();
        getContacts(skype);
    }

how can I make it stop showing the MessageBox and just go straight to loading the form if the user already allowed it in the past (since it doesn't ask to allow it anymore after you've allowed it once)

here is what it looks like, if any are wondering, for some reason; https://i.sstatic.net/gurgQ.jpg, works fine, just want to improve it so any answers to the requests above are appreciated :D

Upvotes: 3

Views: 6689

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

You can prevent showing the message by adding a check box to the dialog so the user can choose "Don't show this message again". Then you can save the value of the check box in settings and based on that setting, decide to show or not to show the dialog.

As a simple solution, you can create your own custom message box:

  1. Create a new Form and name it MessageForm as your custom message box and put buttons like "OK" button and other buttons if you want. And for each button set proper value for DialogResult property. So when you show your form using ShowDialog if you click on a button, without writing code, the form will close with that dialog result.
  2. Add a bool setting to your project Settings file, for example name it DontShow.
  3. Put a check box on form and set its text to "Don't show this message again" and then handle CheckedChanged event and save the value of check box in the DontShow setting:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    Properties.Settings.Default.DontShow = this.checkBox1.Checked;
    Properties.Settings.Default.Save();
}

Now you can show your MessageForm this way:

if(!Properties.Settings.Default.DontShow)
    new MessageForm().ShowDialog();

You can enhance your MessageForm by accepting the message in constructor or even adding a public static void ShowMessage(string) to it to use it like message box.

enter image description here

Upvotes: 5

Related Questions