Esempio n. 1
0
        private void Initialize(object sender, EventArgs e)
        {
            HighDpiHelper.AdjustControlImagesDpiScale(this);
            var settingsPath = GetSettingsPath();

            LoadProgramSettings(settingsPath);
            _settingsWatcher = new FileSystemWatcher
            {
                Path   = Path.GetDirectoryName(settingsPath),
                Filter = Path.GetFileName(settingsPath)
            };
            _settingsWatcher.Changed += (o, args) => LoadProgramSettings(settingsPath);

            ProgramSettingsGrid.BeginInvoke(new Action(() => { ProgramSettingsGrid.SelectedObject = _programSettings; }));

            lock (_settings)
            {
                _settings.ToControls(this);
            }

            // Use exe icon as form icon
            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            // Replicate the right-click menu into the toolbar automatically so I don't have to maintain both
            int indexToInsertAt = toolStrip1.Items.IndexOf(ChannelToolstripItemsSeparator) + 1;

            foreach (var item in contextMenuStrip1.Items.Cast <ToolStripItem>().Reverse())
            {
                ToolStripItem newItem = null;
                switch (item)
                {
                case ToolStripMenuItem _ when item == removeChannelToolStripMenuItem:
                    // This is handled separately
                    continue;

                case ToolStripMenuItem _:
                    newItem = new ToolStripButton
                    {
                        Image        = item.Image,
                        Text         = item.Text,
                        DisplayStyle = ToolStripItemDisplayStyle.Image
                    };
                    newItem.Click += (o, args) => item.PerformClick();
                    break;

                case ToolStripSeparator _:
                    newItem = new ToolStripSeparator();
                    break;
                }

                if (newItem != null)
                {
                    toolStrip1.Items.Insert(indexToInsertAt, newItem);
                }
            }
        }