Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string path = string.Join(Path.DirectorySeparatorChar.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AssemblyProduct, "settings.xml");
            ExeConfigurationFileMap customConfigFileMap = new ExeConfigurationFileMap();

            customConfigFileMap.ExeConfigFilename = path;
            config = ConfigurationManager.OpenMappedExeConfiguration(customConfigFileMap, ConfigurationUserLevel.None);

            // Use case #1, informational message with no response
            SuppressibleMessageBox.Show(config, "msg1", "This message does not return a response", "Test Message #1");

            // Use case #2, evaluate whether or not the message was shown
            DialogResult result = SuppressibleMessageBox.Show(config, "msg2", "This message DOES return a response", "Test Message #2");

            if (result == DialogResult.None)
            {
                MessageBox.Show("The original message was suppressed due to settings");
            }
            else
            {
                MessageBox.Show($"The message box was not suppressed and the result was \"{result.ToString()}\"");
            }
        }
        public static DialogResult Show(Configuration config, string messageId, string message, string caption)
        {
            DialogResult result    = DialogResult.None;
            string       settingId = GetSettingId(messageId);
            bool         suppress;

            bool.TryParse(ReadSetting(config, settingId), out suppress);
            if (!suppress)
            {
                SystemSounds.Beep.Play();
                using (SuppressibleMessageBox frm = new SuppressibleMessageBox(message, caption))
                {
                    result = frm.ShowDialog();
                    if (frm.Suppress)
                    {
                        AddUpdateAppSettings(config, settingId, bool.TrueString);
                    }
                }
            }
            return(result);
        }