Esempio n. 1
0
        private void newBtn_Click(object sender, EventArgs e)
        {
            var createProfile = new SettingsForm(SettingsForm.NEW);

            createProfile.Show();
        }
Esempio n. 2
0
        /// <summary>
        /// Create a context menu and assingn it to notfication tray icon
        /// </summary>
        private void CreateContextMenu()
        {
            // Create context menu and assign it to notification icon
            var progNameMenuItem = new MenuItem(
                $"{Resources.Resources.netchagner}" +
                $" - v{Assembly.GetExecutingAssembly().GetName().Version.ToString()}");

            var profilesMenuItem = new MenuItem {
                Text = Resources.Resources.profiles,
                Name = "profilesMenuItem"
            };
            var profileCreateMenuItem = new MenuItem {
                Text = Resources.Resources.create_new_profile,
                Name = "createProfileMenuItem"
            };
            var editCurrentProfileMenuItem = new MenuItem {
                Text = Resources.Resources.edit_current_profile,
                Name = "editCurrentProfileMenuItem"
            };
            var profileManageMenuItem = new MenuItem {
                Text = Resources.Resources.manage_profiles,
                Name = "profilesManageMenuItem"
            };

            profilesMenuItem.MenuItems.Add(profileCreateMenuItem);
            profilesMenuItem.MenuItems.Add(editCurrentProfileMenuItem);
            profilesMenuItem.MenuItems.Add(profileManageMenuItem);
            profilesMenuItem.MenuItems.Add("-");

            // adding profiles to the sub menu again.
            foreach (var item in Profiles)
            {
                var menuItem = new MenuItem {
                    Text       = item.Name,
                    Name       = item.Name + "MenuItem",
                    RadioCheck = true,
                    Checked    = Net.Profile != null && Net.Profile.Name != null?
                                 Net.Profile.Name.Equals(item.Name) : true
                };
                menuItem.Click += ProfileMenuItemClick;
                profilesMenuItem.MenuItems.Add(menuItem);
            }

            var languageMenuItem = new MenuItem {
                Text = Resources.Resources.language,
                Name = "languageMenuItem"
            };

            var englishLanguageMenuItem = new MenuItem {
                Text       = Resources.Resources.en,
                Name       = "englishLanguageMenuItem",
                Tag        = "en-US",
                RadioCheck = true,
                Checked    = Thread.CurrentThread.CurrentCulture.Name == "en-US",
            };

            englishLanguageMenuItem.Click += LanguageSelect;
            var persianLanguageMenuItem = new MenuItem {
                Text       = Resources.Resources.fa,
                Name       = "persianLanguageMenuItem",
                Tag        = "fa-IR",
                RadioCheck = true,
                Checked    = Thread.CurrentThread.CurrentCulture.Name == "fa-IR"
            };

            persianLanguageMenuItem.Click += LanguageSelect;

            languageMenuItem.MenuItems.Add(englishLanguageMenuItem);
            languageMenuItem.MenuItems.Add(persianLanguageMenuItem);

            var showLogMenuItem = new MenuItem {
                Text = Resources.Resources.show_log,
                Name = "showLogMenuItem"
            };

            var startupMenuItem = new MenuItem {
                Text = Resources.Resources.put_in_startup,
                Name = "startupMenuItem"
            };

            var aboutMenuItem = new MenuItem {
                Text = Resources.Resources.about,
                Name = "aboutMenuItem"
            };
            var quitMenuItem = new MenuItem(Resources.Resources.quit);
            var contextMenu  = new ContextMenu();

            contextMenu.MenuItems.Add(progNameMenuItem);
            contextMenu.MenuItems.Add("-");
            contextMenu.MenuItems.Add(profilesMenuItem);
            contextMenu.MenuItems.Add(languageMenuItem);
            contextMenu.MenuItems.Add("-");
            contextMenu.MenuItems.Add(showLogMenuItem);
            contextMenu.MenuItems.Add(startupMenuItem);
            contextMenu.MenuItems.Add(aboutMenuItem);
            contextMenu.MenuItems.Add("-");
            contextMenu.MenuItems.Add(quitMenuItem);
            notifyIcon.ContextMenu = contextMenu;

            // If there is a shortcut of app in startup folder put check mark for the menu item
            var exeName = System.IO.Path.GetFileNameWithoutExtension(
                System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

            startupMenuItem.Checked =
                System.IO.File.Exists(
                    Environment.GetFolderPath(Environment.SpecialFolder.Startup) + $"\\{exeName}.lnk");

            #region Context Menu Events Wire Up
            // Wire up menu items event handlers
            quitMenuItem.Click    += QuitMenuItemClick;
            startupMenuItem.Click += StartupMenuItemClick;

            // Wire up create profiles menu item to show profile form (settings actually)
            profileCreateMenuItem.Click += (s, e) => {
                var createProfile = new SettingsForm(SettingsForm.NEW);
                createProfile.Show();
            };

            // Wire up edit current profile menu item to show profile form (settings actually) for the active profile
            editCurrentProfileMenuItem.Click += (s, e) => {
                var editCurrentProfile = new SettingsForm(SettingsForm.EDIT_CURRENT);
                editCurrentProfile.Show();
            };

            // Wire up manage profiles menu item to show the form
            profileManageMenuItem.Click += (s, e) => {
                var manageProfiles = new ManageProfiles();
                manageProfiles.Show();
            };

            // Wire up show log menu item to show the form
            showLogMenuItem.Click += (s, e) => {
                var showLog = new ShowLog();
                showLog.Show();
            };

            // Wire up about menu item to show about form
            aboutMenuItem.Click += (s, e) => {
                var about = new AboutForm();
                about.Show();
            };
            #endregion
        }
Esempio n. 3
0
        private void editBtn_Click(object sender, EventArgs e)
        {
            var editProfile = new SettingsForm(profilesLbx.SelectedItem.ToString());

            editProfile.Show();
        }