/// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     if (!saved)
     {
         if (MessageBox.Show($"{LocalStrings.Exit_no_save}", $"{LocalStrings.Info}", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
         {
             return;
         }
     }
     ConfigSaver.Font     = richTextBox.Font;
     ConfigSaver.FormSize = this.Size;
     ConfigSaver.Save();
     if (disposing && (components != null))
     {
         components.Dispose();
     }
     base.Dispose(disposing);
 }
Пример #2
0
        public MainWindow(string path)
        {
            InitializeComponent();

            ConfigSaver = new ConfigSaver();

            if (!ConfigSaver.IsAssociated || !FileAssociation.IsAssociated())
            {
                FileAssociation.Associate($"{LocalStrings.Description}", Assembly.GetExecutingAssembly().Location);
                FileAssociation.AddToContextMenuNew();
                ConfigSaver.IsAssociated = true;
            }

            this.Width       = ConfigSaver.FormSize.Width;
            this.Height      = ConfigSaver.FormSize.Height;
            richTextBox.Font = ConfigSaver.Font;

            //All events are here
            richTextBox.TextChanged += (s, e) =>
            {
                saved           = false;
                lbl_status.Text = $"{LocalStrings.TotalChars}: {richTextBox.Text.Length}";
            };
            tool_new.Click           += new System.EventHandler(tool_new_Click);
            tool_open.Click          += new EventHandler(tool_open_Click);
            tool_save.Click          += new EventHandler(tool_save_Click);
            tool_saveAs.Click        += new System.EventHandler(tool_saveAs_Click);
            tool_fontSettings.Click  += new EventHandler(tool_fontSettings_Click);
            tool_replace.Click       += new EventHandler(tool_replace_Click);
            tool_about.Click         += new EventHandler(tool_about_Click);
            tool_exit.Click          += new System.EventHandler(tool_exit_Click);
            tool_deleteProgram.Click += new System.EventHandler(tool_deleteProgram_Click);
            Shown += (s, e) =>
            {
                //update ui
                #region
                new Thread(() =>
                {
                    while (true)
                    {
                        try
                        {
                            this.Invoke(new MethodInvoker(() =>
                            {
                                string t  = (saved) ? "" : "*";
                                this.Text = Path.GetFileName(FilePath) + t;
                                try
                                {
                                    progressBar.Maximum = MaxValueProgress;
                                    progressBar.Value   = ValueProgress;
                                }
                                catch { }
                            }));
                            Thread.Sleep(250);
                        }
                        catch { }
                    }
                })
                {
                    IsBackground = true
                }.Start();
                #endregion
                if (path == "")
                {
                    return;
                }
                LoadFile(path);
            };
        }