创建一个消息框,用户可以选择“不再显示". [英] Create a message box that user can choose to "Don't show it again."

查看:24
本文介绍了创建一个消息框,用户可以选择“不再显示".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

制作了一个大众信使 &多消息/垃圾邮件发送者合二为一,工作正常,只是想让它变得更好.显然,我必须编写代码才能让 Skype 允许该程序,以便它可以做它所做的事情,这里是,

 private void Form1_Load(object sender, EventArgs e){//我输入了一个消息框,所以它不会立即崩溃.MessageBox.Show("请允许SkypeBot.vshost.exe访问Skype.(看看你的Skype应用程序)");Skype Skype = 新的 Skype();skype.Attach();获取联系人(Skype);}

如果用户过去已经允许它,我怎样才能让它停止显示 MessageBox 并直接加载表单(因为它在你允许一次后不再要求允许它)

>

这里是它的样子,如果有人想知道,出于某种原因;

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; http://imgur.com/f0aaiZN, works fine, just want to improve it so any answers to the requests above are appreciated :D

解决方案

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.

这篇关于创建一个消息框,用户可以选择“不再显示".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆