private void writeXmlConfigDataButton_Click(object sender, EventArgs e)
        {
            EditorFontData configData = new EditorFontData();

            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                configData.Name  = fontDialog.Font.Name;
                configData.Size  = fontDialog.Font.Size;
                configData.Style = Convert.ToInt32(fontDialog.Font.Style);

                // Write the new configuration data to the XML file
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.Sections.Remove("EditorSettings");
                config.Sections.Add("EditorSettings", configData);
                config.Save();


                StringBuilder results = new StringBuilder();
                results.Append("Configuration Data Updated:");
                results.Append(Environment.NewLine);
                results.Append('\t');
                results.Append(configData.ToString());

                DisplayResults(results.ToString(), writeResultsTextBox);

                this.UpdateFont(configData, writeSampleTextBox);
            }
        }
 private void ShowFontData(EditorFontData fontData, RichTextBox sampleTextBox)
 {
     if (fontData != null)
     {
         Font newFont = new Font(fontData.Name, fontData.Size, (FontStyle)fontData.Style);
         sampleTextBox.Font = newFont;
     }
 }
 private void UpdateFont(EditorFontData fontData, RichTextBox sampleTextBox)
 {
     if (sampleTextBox.InvokeRequired)
     {
         readSampleTextBox.Invoke(new ShowFontDataDelegate(ShowFontData), new object[] { fontData, sampleTextBox });
     }
     else
     {
         ShowFontData(fontData, sampleTextBox);
     }
 }
        private void QuickStartForm_Load(object sender, System.EventArgs e)
        {
            // Initialize image to embedded logo
            this.logoPictureBox.Image = GetEmbeddedImage("ConfigurationReadXmlQuickStart.logo.gif");

            // Initialize the text box with the configuration settings
            EditorFontData configData = ConfigurationManager.GetSection("EditorSettings") as EditorFontData;

            // Initialize file system watcher
            watcher                     = new FileSystemWatcher(AppDomain.CurrentDomain.BaseDirectory);
            watcher.Changed            += new FileSystemEventHandler(watcher_Changed);
            watcher.EnableRaisingEvents = false;


            DisplayResults("Application configuration loaded.", readResultsTextBox);

            this.UpdateFont(configData, readSampleTextBox);
        }
        private void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            if (e.FullPath.ToLower().Contains(".config"))
            {
                for (int i = 0; i < 3; i++)
                {
                    try
                    {
                        // Using the static method, read the cached configuration settings
                        ConfigurationManager.RefreshSection("EditorSettings");
                        break;
                    }
                    catch (ConfigurationErrorsException)
                    {
                        if (i == 2)
                        {
                            throw;
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                }

                EditorFontData configData = ConfigurationManager.GetSection("EditorSettings") as EditorFontData;

                StringBuilder results = new StringBuilder();
                results.Append("Configuration changes in storage were detected. Updating configuration.");
                results.Append(Environment.NewLine);
                results.Append("New configuration settings:");
                results.Append(Environment.NewLine);
                results.Append('\t');
                results.Append(configData.ToString());
                results.Append(Environment.NewLine);

                DisplayResults(results.ToString(), readResultsTextBox);

                this.UpdateFont(configData, readSampleTextBox);
            }
        }
        /// <summary>
        /// Use case: demonstrate how to retrieve configuration data
        /// </summary>
        private void readXmlConfigDataButton_Click(object sender, System.EventArgs e)
        {
            Cursor = System.Windows.Forms.Cursors.WaitCursor;

            // Using the static method, read the cached configuration settings
            EditorFontData configData = ConfigurationManager.GetSection("EditorSettings") as EditorFontData;

            StringBuilder results = new StringBuilder();

            results.Append("Configuration settings:");
            results.Append(Environment.NewLine);
            results.Append('\t');
            results.Append(configData.ToString());
            results.Append(Environment.NewLine);

            DisplayResults(results.ToString(), readResultsTextBox);

            this.UpdateFont(configData, readSampleTextBox);

            Cursor = System.Windows.Forms.Cursors.Arrow;
        }
Esempio n. 7
0
        private void writeXmlConfigDataButton_Click(object sender, EventArgs e)
        {
            EditorFontData configData = new EditorFontData();

            if (fontDialog.ShowDialog() == DialogResult.OK)
            {
                configData.Name = fontDialog.Font.Name;
                configData.Size = fontDialog.Font.Size;
                configData.Style = Convert.ToInt32(fontDialog.Font.Style);

                // Write the new configuration data to the XML file
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.Sections.Remove("EditorSettings");
                config.Sections.Add("EditorSettings", configData);
                config.Save();


                StringBuilder results = new StringBuilder();
                results.Append("Configuration Data Updated:");
                results.Append(Environment.NewLine);
                results.Append('\t');
                results.Append(configData.ToString());

                DisplayResults(results.ToString(), writeResultsTextBox);

                this.UpdateFont(configData, writeSampleTextBox);
            }
        }
Esempio n. 8
0
        private void ShowFontData(EditorFontData fontData, RichTextBox sampleTextBox)
		{
            if (fontData != null)
            {
                Font newFont = new Font(fontData.Name, fontData.Size, (FontStyle)fontData.Style);
                sampleTextBox.Font = newFont;
            }
		}
Esempio n. 9
0
		private void UpdateFont(EditorFontData fontData, RichTextBox sampleTextBox)
		{
            if (sampleTextBox.InvokeRequired)
			{
                readSampleTextBox.Invoke(new ShowFontDataDelegate(ShowFontData), new object[] { fontData, sampleTextBox });
			}
			else
			{
                ShowFontData(fontData, sampleTextBox);
			}
		}