public ServerWindow()
 {
     InitializeComponent();
     Closing += ServerWindow_Closing;
     isConfigured = false;
     isConnected = false;
     isServerActive = false;
     passwordChanged = false;
     notifyServer = new System.Windows.Forms.NotifyIcon();
     notifyServer.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyServer_mouseClickEvent);
     notifyServer.MouseMove += new System.Windows.Forms.MouseEventHandler(notifyServer_MouseMove);
     path = Directory.GetCurrentDirectory().Remove(Directory.GetCurrentDirectory().Length - 9);
     notifyServer.Icon = new System.Drawing.Icon(path + "\\Punto_rosso.ico");
     status = new StatusWindow(this);
     this.WindowState = WindowState.Normal;
     this.ShowInTaskbar = true; //cosi non compare l'icona
     notifyServer.Visible = true;
     notifyServer.BalloonTipTitle = "Server AVVIATO";
     notifyServer.BalloonTipText = "Caricate le impostazioni di default\nPremi START per mettere il server in attesa di connessioni";
     notifyServer.ShowBalloonTip(300);
     connectionParameter = new ConnectionParameter();
     dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
     //questo metodo mi serve per inserire tutti gli indirizzi presente sulla macchina server
     caricaInfoIndirizzoServer();
     caricaInfoTextBox();
     stopButton.IsEnabled = false;
     stateLabel.Content = NON_CONNESSO;
     contHour = 0;
     contMin = 0;
     contSec = 0;
 }
Esempio n. 2
0
 public void ShowNotification(String message)
 {
     var notification = new System.Windows.Forms.NotifyIcon()
     {
         Visible = true,
         Icon = System.Drawing.SystemIcons.Information,
         BalloonTipText = message,
     };
     notification.ShowBalloonTip(60);
 }
Esempio n. 3
0
        private System.Windows.Forms.NotifyIcon CreateIcon()
        {
            icon = new System.Windows.Forms.NotifyIcon();
            icon.Visible = true;
            icon.Icon = new System.Drawing.Icon("small-orange-sphere.ico");
            icon.ContextMenu = GetContextMenu();

            icon.ShowBalloonTip(3, "BeCharming", "Ready to receive shared items...", System.Windows.Forms.ToolTipIcon.Info);

            return icon;
        }
Esempio n. 4
0
 private void MainWindow_OnStateChanged(object sender, EventArgs e)
 {
     if (WindowState == WindowState.Minimized)
     {
         Hide();
         m_notifyIcon?.ShowBalloonTip(2000);
     }
     else
     {
         m_storedWindowState = WindowState;
     }
 }
        private void InitialTray()
        {
            //设置托盘的各个属性
            notifyIcon = new System.Windows.Forms.NotifyIcon();
            notifyIcon.BalloonTipText = "程序开始运行";
            string s = "OfficeScan (Online)\r\nAntivirus \r\nDCS Eng/Ptn:7.0.1028/1268";
            notifyIcon.Text = s;
            notifyIcon.Icon = new System.Drawing.Icon("favicon2.ico");
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(1000);
            notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);

            //设置菜单项
            System.Windows.Forms.MenuItem[] menuitems =
            {
                new System.Windows.Forms.MenuItem("OfficeScan Console"),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("Component Versions"),
                new System.Windows.Forms.MenuItem("Update Now"),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("Enable Roaming Mode"),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("Scheduled Scan Advanced Settings"),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("Plug-in Manager"),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("Unload OfficeScan")
            };

            System.Windows.Forms.MenuItem menu1 = new System.Windows.Forms.MenuItem("OfficeScan Console");
            System.Windows.Forms.MenuItem menu2 = new System.Windows.Forms.MenuItem("菜单项2");
            //分隔线!!
            System.Windows.Forms.MenuItem menu3 = new System.Windows.Forms.MenuItem("-");
            ////退出菜单项
            //System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("exit");
            //exit.Click += new EventHandler(exit_Click);

            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = menuitems;
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            //窗体状态改变时候触发
            this.StateChanged += new EventHandler(SysTray_StateChanged);
        }
Esempio n. 6
0
        private void initNotifyIcon()
        {
            notifyIcon = new System.Windows.Forms.NotifyIcon();
            notifyIcon.BalloonTipText = "Brilliantech Warehouse Print Serivce";
            notifyIcon.Text = "Brilliantech Warehouse Print Serivce";
            string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "i.ico");
            notifyIcon.Icon = new System.Drawing.Icon(path);
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(2000);
            notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);

            System.Windows.Forms.MenuItem item1 = new System.Windows.Forms.MenuItem("Menu 1");

            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");

            exit.Click += new EventHandler(exit_Click);

            System.Windows.Forms.MenuItem[] menus = new System.Windows.Forms.MenuItem[] { exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(menus);
            this.StateChanged += new EventHandler(MainWindow_StateChanged);
        }
Esempio n. 7
0
        private void initNotifyIcon()
        {
            ZigBeeIdLab.Content = SerialPortConfig.ZigBeeId;
            ServicePortLab.Content = SerialPortConfig.ServicePort;

            notifyIcon = new System.Windows.Forms.NotifyIcon();
            notifyIcon.BalloonTipText = "BW LED " + SerialPortConfig.ZigBeeId + "(" + SerialPortConfig.ServicePort + ") Serivce";
            notifyIcon.Text = "BW LED " + SerialPortConfig.ZigBeeId + "(" + SerialPortConfig.ServicePort + ") LED Serivce";
            string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "i.ico");
            notifyIcon.Icon = new System.Drawing.Icon(path);
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(2000);
            notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);

            System.Windows.Forms.MenuItem item1 = new System.Windows.Forms.MenuItem("Menu 1");

            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");

            exit.Click += new EventHandler(exit_Click);

            System.Windows.Forms.MenuItem[] menus = new System.Windows.Forms.MenuItem[] { exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(menus);
            this.StateChanged += new EventHandler(MainWindow_StateChanged);
        }
Esempio n. 8
0
        private static void SetupTrayIcon(string logFileName)
        {
            // Create tray icon
            var components = new System.ComponentModel.Container();

            var notifyIcon = new System.Windows.Forms.NotifyIcon(components);
            notifyIcon.Text = "Paradox Connection Router";
            notifyIcon.Icon = Properties.Resources.Logo;
            notifyIcon.Visible = true;
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();

            if (!string.IsNullOrEmpty(logFileName))
            {
                var showLogMenuItem = new System.Windows.Forms.MenuItem("Show &Log");
                showLogMenuItem.Click += (sender, args) => OnShowLogClick(logFileName);
                notifyIcon.ContextMenu.MenuItems.Add(showLogMenuItem);

                notifyIcon.BalloonTipClicked += (sender, args) => OnShowLogClick(logFileName);
            }

            var openConsoleMenuItem = new System.Windows.Forms.MenuItem("Open Console");
            openConsoleMenuItem.Click += (sender, args) => OnOpenConsoleClick((System.Windows.Forms.MenuItem)sender);
            notifyIcon.ContextMenu.MenuItems.Add(openConsoleMenuItem);

            var exitMenuItem = new System.Windows.Forms.MenuItem("E&xit");
            exitMenuItem.Click += (sender, args) => OnExitClick();
            notifyIcon.ContextMenu.MenuItems.Add(exitMenuItem);

            GlobalLogger.GlobalMessageLogged += (logMessage) =>
            {
                System.Windows.Forms.ToolTipIcon toolTipIcon;
                switch (logMessage.Type)
                {
                    case LogMessageType.Debug:
                    case LogMessageType.Verbose:
                    case LogMessageType.Info:
                        toolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
                        break;
                    case LogMessageType.Warning:
                        toolTipIcon = System.Windows.Forms.ToolTipIcon.Warning;
                        break;
                    case LogMessageType.Error:
                    case LogMessageType.Fatal:
                        toolTipIcon = System.Windows.Forms.ToolTipIcon.Error;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                // Display notification (for one second)
                notifyIcon.ShowBalloonTip(2000, "Paradox Connection Router", logMessage.ToString(), toolTipIcon);
            };

            System.Windows.Forms.Application.ApplicationExit += (sender, e) =>
            {
                notifyIcon.Visible = false;
                notifyIcon.Icon = null;
                notifyIcon.Dispose();
            };
        }
Esempio n. 9
0
        private void CreateNotifyIcon()
        {
            //create menu
            var main = new System.Windows.Forms.ContextMenu();

            var restore = new System.Windows.Forms.MenuItem
                              {
                                  Text = "Show Interface..."
                              };
            restore.Click += new EventHandler(restore_Click);
            main.MenuItems.Add(restore);

            var refresh = new System.Windows.Forms.MenuItem
            {
                Name = "refresh",
                Text = "Refresh Now"
            };
            refresh.Click += new EventHandler(refresh_Click);
            main.MenuItems.Add(refresh);

            var tipOption = new System.Windows.Forms.MenuItem
            {
                Text = _config.ShowBalloonTip ? "Disable Balloon" : "Enable Balloon"
            };
            tipOption.Click += new EventHandler(notifyIcon_BalloonTipClicked);
            main.MenuItems.Add(tipOption);

            var configureOption = new System.Windows.Forms.MenuItem
            {
                Name = "configure",
                Text = "Configure Media Browser..."
            };
            configureOption.Click += new EventHandler(configure_Click);
            main.MenuItems.Add(configureOption);

            var sep = new System.Windows.Forms.MenuItem
                          {
                              Text = "-"
                          };
            main.MenuItems.Add(sep);

            var exit = new System.Windows.Forms.MenuItem
                           {
                               Name = "exit",
                               Text = "Exit"
                           };
            exit.Click += new EventHandler(exit_Click);
            main.MenuItems.Add(exit);

            //set up our systray icon
            Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/MediaBrowserService;component/MBService.ico")).Stream;
            notifyIcon = new System.Windows.Forms.NotifyIcon
                             {
                                 BalloonTipTitle = "Media Browser Service",
                                 BalloonTipText = "Running in background. Use tray icon to configure...",
                                 Text = "Media Browser Service",
                                 Icon = new System.Drawing.Icon(iconStream),
                                 ContextMenu = main,
                                 Visible = true
                             };
            notifyIcon.DoubleClick += notifyIcon_Click;
            notifyIcon.BalloonTipClicked += new EventHandler(notifyIcon_BalloonTipClicked);
            if (_config.ShowBalloonTip) notifyIcon.ShowBalloonTip(2000);

            //create our refresh icons
            iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/MediaBrowserService;component/MBServiceRefresh.ico")).Stream;
            RefreshIcons[0] = new System.Drawing.Icon(iconStream);
            iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/MediaBrowserService;component/MBServiceRefresh2.ico")).Stream;
            RefreshIcons[1] = new System.Drawing.Icon(iconStream);
        }
Esempio n. 10
0
        private void loadNotifyIcon(string cliente)
        {
            notifyIcon = new System.Windows.Forms.NotifyIcon();

            notifyIcon.Icon = System.Drawing.Icon.FromHandle(Properties.Resources.information.GetHicon());
            notifyIcon.BalloonTipText = cliente + " ha pernottato " + Properties.Settings.Default.CadenzaPremioSoggiorni + " volte alla Fattoria Pianetti!"; // Text of BalloonTip 
            notifyIcon.Text = "Premio cliente raggiunto"; // ToolTip of NotifyIcon 
            notifyIcon.BalloonTipTitle = "Cliente ha raggiunto il premio soggiorni";
            notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
            notifyIcon.Visible = true;
            notifyIcon.Text = "Premio cliente";
            notifyIcon.ShowBalloonTip(1000); // Shows BalloonTip 

            notifyIcon.Click += new System.EventHandler(NotifyIcon_Click);

        }
Esempio n. 11
0
        private void InitSysTray()
        {
            var rs = Application.GetResourceStream(new Uri("pack://application:,,,/search.ico"));
            var ni = new System.Windows.Forms.NotifyIcon();

            ni.Icon = new System.Drawing.Icon(rs.Stream);

            ni.Visible = true;
            ni.DoubleClick +=
                delegate (object sender, EventArgs args)
                {
                    this.Show();
                    this.WindowState = WindowState.Normal;
                };
            ni.Text = "HyperSearch - Double click to open log";

            var ctx = new System.Windows.Forms.ContextMenu();

            ctx.MenuItems.Add(new System.Windows.Forms.MenuItem("View log", (ss, ee) => { this.Show(); this.WindowState = System.Windows.WindowState.Normal; }));
            ctx.MenuItems.Add(new System.Windows.Forms.MenuItem("Exit", (ss, ee) => { Application.Current.Shutdown(); }));

            ni.ContextMenu = ctx;

            int balloonToolTipTimeoutInsMS = HyperSearchSettings.Instance().General.BalloonToolTipTimeOutInMilliseconds;

            if (balloonToolTipTimeoutInsMS > 0)
            {
                ni.ShowBalloonTip(balloonToolTipTimeoutInsMS, "HyperSearch started", "Double click tray icon to bring up log window.", System.Windows.Forms.ToolTipIcon.Info);
            }
        }
Esempio n. 12
0
        private static void SetupTrayIcon(string logFileName)
        {
            // Create tray icon
            var components = new System.ComponentModel.Container();

            var notifyIcon = new System.Windows.Forms.NotifyIcon(components);
            notifyIcon.Text = "Xenko Connection Router";
            notifyIcon.Icon = Properties.Resources.Logo;
            notifyIcon.Visible = true;
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();

            if (!string.IsNullOrEmpty(logFileName))
            {
                var showLogMenuItem = new System.Windows.Forms.MenuItem("Show &Log");
                showLogMenuItem.Click += (sender, args) => OnShowLogClick(logFileName);
                notifyIcon.ContextMenu.MenuItems.Add(showLogMenuItem);

                notifyIcon.BalloonTipClicked += (sender, args) => OnShowLogClick(logFileName);
            }

            var openConsoleMenuItem = new System.Windows.Forms.MenuItem("Open Console");
            openConsoleMenuItem.Click += (sender, args) => OnOpenConsoleClick((System.Windows.Forms.MenuItem)sender);
            notifyIcon.ContextMenu.MenuItems.Add(openConsoleMenuItem);

            var exitMenuItem = new System.Windows.Forms.MenuItem("E&xit");
            exitMenuItem.Click += (sender, args) => OnExitClick();
            notifyIcon.ContextMenu.MenuItems.Add(exitMenuItem);

            GlobalLogger.GlobalMessageLogged += (logMessage) =>
            {
                // Log only warning, errors and more
                if (logMessage.Type < LogMessageType.Warning)
                    return;

                var toolTipIcon = logMessage.Type < LogMessageType.Error ? System.Windows.Forms.ToolTipIcon.Warning : System.Windows.Forms.ToolTipIcon.Error;

                // Display notification (for two second)
                notifyIcon.ShowBalloonTip(2000, "Xenko Connection Router", logMessage.ToString(), toolTipIcon);
            };

            System.Windows.Forms.Application.ApplicationExit += (sender, e) =>
            {
                notifyIcon.Visible = false;
                notifyIcon.Icon = null;
                notifyIcon.Dispose();
            };
        }
Esempio n. 13
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _this = this;

            notifyIcon = new System.Windows.Forms.NotifyIcon();
            notifyIcon.BalloonTipText = "程序开始运行";
            notifyIcon.BalloonTipTitle = "NewsApp";
            notifyIcon.Text = "NewsApp Tray";
            notifyIcon.Icon = System.Drawing.SystemIcons.WinLogo;
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(1000);
            notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[]
            {
                new System.Windows.Forms.MenuItem("关于", (obj, args) =>
                    System.Windows.MessageBox.Show(this, "NewsApp by bajdcc", "NewsApp")),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("显示主界面", (obj, args) =>
                    Show()),
                new System.Windows.Forms.MenuItem("隐藏主界面", (obj, args) =>
                    Hide()),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("显示新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Overlay.Show();
                        }
                    }),
                new System.Windows.Forms.MenuItem("隐藏新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Overlay.Hide();
                        }
                    }),
                new System.Windows.Forms.MenuItem("关闭新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    }),
                new System.Windows.Forms.MenuItem("背景透明", (obj, args) =>
                    {
                        NewsMachine.Settings.TransparentBackground = !NewsMachine.Settings.TransparentBackground;
                        var _this = obj as System.Windows.Forms.MenuItem;
                        _this.Checked = !_this.Checked;
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    })
                {
                    Checked = false
                },
                new System.Windows.Forms.MenuItem("鼠标穿透", (obj, args) =>
                    {
                        NewsMachine.Settings.TransparentWindow = !NewsMachine.Settings.TransparentWindow;
                        var _this = obj as System.Windows.Forms.MenuItem;
                        _this.Checked = !_this.Checked;
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    })
                {
                    Checked = true
                },
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("手动刷新", (obj, args) =>
                    {
                        if (_newsMachine != null)
                        {
                            _newsMachine.Reset();
                        }
                    }),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("退出", (obj, args) =>
                    AnimateClose())
            });

            _newsMachine = new NewsMachine();
            _newsMachine.OnLogging += TraceOutput;
            _newsMachine.MainDispatcher = Dispatcher;
            _newsMachine.Start();
        }
Esempio n. 14
0
        /// <inheritdoc/>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            // Restore window position. Please mind that screen's real-estate might have changed since the previous launch.
            if (!double.IsNaN(Properties.Settings.Default.WindowLeft))
            {
                Left = Math.Min(Math.Max(Properties.Settings.Default.WindowLeft, SystemParameters.VirtualScreenLeft), SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - Width);
            }
            if (!double.IsNaN(Properties.Settings.Default.WindowTop))
            {
                Top = Math.Min(Math.Max(Properties.Settings.Default.WindowTop, SystemParameters.VirtualScreenTop), SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - Height);
            }

            Application.Current.SessionEnding += (object sender, SessionEndingCancelEventArgs e_session_end) =>
            {
                // Save window position on logout.
                Properties.Settings.Default.WindowTop  = Top;
                Properties.Settings.Default.WindowLeft = Left;
            };

            // Preload icons to be used on system tray.
            var icon_size = System.Windows.Forms.SystemInformation.SmallIconSize;

            _icons = new Dictionary <VPNSessionStatusType, Icon>();
            foreach (var status_type in Enum.GetValues(typeof(VPNSessionStatusType)).Cast <VPNSessionStatusType>())
            {
                var icon_uri = new Uri(String.Format("pack://application:,,,/Resources/VPNSessionStatusTypeIcon{0}.ico", Enum.GetName(typeof(VPNSessionStatusType), status_type)));
                try { _icons.Add(status_type, new Icon(Application.GetResourceStream(icon_uri).Stream, icon_size)); }
                catch { _icons.Add(status_type, new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/VPNSessionStatusTypeIconInitializing.ico")).Stream, icon_size)); }
            }

            // Attach to view model events.
            var view_model = (ViewModels.Windows.ConnectWizard)DataContext;

            view_model.RequestInstanceAuthorization                 += ConnectWizard_RequestInstanceAuthorization;
            view_model.RequestOpenVPNPasswordAuthentication         += ConnectWizard_RequestOpenVPNPasswordAuthentication;
            view_model.RequestOpenVPNUsernamePasswordAuthentication += ConnectWizard_RequestOpenVPNUsernamePasswordAuthentication;
            view_model.PromptSelfUpdate += ConnectWizard_PromptSelfUpdate;
            view_model.QuitApplication  += ConnectWizard_QuitApplication;

            // Create notify icon, set default icon, and setup events.
            // We need to do this programatically, since System.Windows.Forms.NotifyIcon is not WPF, but borrowed from WinForms.
            _tray_icon = new System.Windows.Forms.NotifyIcon()
            {
                Text = TrayIconToolTipText,
                Icon = TrayIcon
            };
            _tray_icon.Click += TrayIcon_Click;

            // Bind to "ActiveSession.StateDescription" and "ActiveSession.State" property to keep tray icon up-to-date.
            view_model.PropertyChanged += (object sender, PropertyChangedEventArgs e2) =>
            {
                if (e2.PropertyName == nameof(view_model.ActiveSession))
                {
                    // Active session changed: sync the tray icon.
                    _tray_icon.Text = TrayIconToolTipText;
                    _tray_icon.Icon = TrayIcon;

                    if (view_model.ActiveSession != VPNSession.Blank)
                    {
                        // Initialize VPN session state.
                        _session_state = view_model.ActiveSession.State;

                        // Bind to the session for property changes.
                        view_model.ActiveSession.PropertyChanged += (object sender_Session, PropertyChangedEventArgs e_Session) =>
                        {
                            switch (e_Session.PropertyName)
                            {
                            case nameof(view_model.ActiveSession.ConnectingProfile):
                            case nameof(view_model.ActiveSession.StateDescription):
                                _tray_icon.Text = TrayIconToolTipText;
                                break;

                            case nameof(view_model.ActiveSession.State):
                            {
                                _tray_icon.Icon = TrayIcon;

                                if (!IsVisible)
                                {
                                    // Client is minimized.
                                    switch (view_model.ActiveSession.State)
                                    {
                                    case VPNSessionStatusType.Connected:
                                        // Client connected. Popup the balloon message.
                                        _tray_icon.ShowBalloonTip(
                                            5000,
                                            String.Format(Views.Resources.Strings.SystemTrayBalloonConnectedTitle, view_model.ActiveSession.ConnectingProfile),
                                            String.Format(Views.Resources.Strings.SystemTrayBalloonConnectedMessage, view_model.ActiveSession.TunnelAddress, view_model.ActiveSession.IPv6TunnelAddress),
                                            System.Windows.Forms.ToolTipIcon.Info);
                                        break;

                                    default:
                                        if (_session_state == VPNSessionStatusType.Connected)
                                        {
                                            // Client has been disconnected. Popup the balloon message.
                                            _tray_icon.ShowBalloonTip(
                                                5000,
                                                eduVPN.Properties.Settings.Default.ClientTitle,
                                                Views.Resources.Strings.SystemTrayBalloonDisconnectedMessage,
                                                System.Windows.Forms.ToolTipIcon.Info);
                                        }
                                        break;
                                    }
                                }

                                // Save VPN session state.
                                _session_state = view_model.ActiveSession.State;
                            }
                            break;
                            }
                        };
                    }
                }
            };

            Loaded  += Window_Loaded;
            Closing += Window_Closing;

            // Set context menu data context to allow bindings to work.
            if (Resources["SystemTrayMenu"] is ContextMenu menu)
            {
                menu.DataContext = DataContext;
            }
        }
Esempio n. 15
0
        public MainWindow()
        {
            InitializeComponent();

            Instance = this;

            #region Init Timer
            DTimer = new DispatcherTimer(TimeSpan.FromSeconds(1),
                                         DispatcherPriority.Normal,
                                         (s, e) =>
            {
                _seconds++;

                if (_seconds == 60)
                {
                    _seconds = 0;
                    _minutes++;
                }

                // If Capture Duration is set
                if (_duration > 0 && (_minutes * 60 + _seconds >= _duration))
                {
                    StopRecording();
                    SystemSounds.Exclamation.Play();

                    // SystemTray Notification
                    if (SystemTray.Visible)
                    {
                        SystemTray.ShowBalloonTip(3000, "Capture Completed",
                                                  $"Capture Completed in {OtherSettings.CaptureDuration} seconds",
                                                  System.Windows.Forms.ToolTipIcon.None);
                    }
                }

                TimeManager.Content = $"{_minutes:D2}:{_seconds:D2}";
            },
                                         TimeManager.Dispatcher)
            {
                IsEnabled = false
            };
            #endregion

            //Populate Available Codecs, Audio and Video Sources ComboBoxes
            Refresh();

            #region Command Bindings
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (s, e) =>
            {
                var dlg = new FolderBrowserDialog
                {
                    SelectedPath = OutPath.Text,
                    Title        = "Select Output Folder"
                };

                if (!dlg.ShowDialog().Value)
                {
                    return;
                }

                OutPath.Text = dlg.SelectedPath;
                Settings.Default.OutputPath = dlg.SelectedPath;
                Settings.Default.Save();
            }));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => StartRecording(),
                                                   (s, e) => e.CanExecute = ReadyToRecord));

            CommandBindings.Add(new CommandBinding(ApplicationCommands.Stop, (s, e) => StopRecording(),
                                                   (s, e) => e.CanExecute = !ReadyToRecord));

            CommandBindings.Add(new CommandBinding(NavigationCommands.Refresh, (s, e) => Refresh()));

            CommandBindings.Add(new CommandBinding(PauseCommand, (s, e) =>
            {
                Recorder.Pause();
                DTimer.Stop();

                PauseButton.Command  = ResumeCommand;
                RotationEffect.Angle = 90;
                Status.Content       = "Paused";
                PauseButton.ToolTip  = "Pause";
            }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null));

            CommandBindings.Add(new CommandBinding(ResumeCommand, (s, e) =>
            {
                Recorder.Start();
                DTimer.Start();

                PauseButton.Command  = PauseCommand;
                RotationEffect.Angle = 0;
                Status.Content       = "Recording...";
                PauseButton.ToolTip  = "Resume";
            }, (s, e) => e.CanExecute = !ReadyToRecord && Recorder != null));
            #endregion

            #region SystemTray
            SystemTray = new NotifyIcon
            {
                Visible = false,
                Text    = "Captura",
                Icon    = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location)
            };

            SystemTray.Click += (s, e) =>
            {
                SystemTray.Visible = false;
                Show();
                WindowState = WindowState.Normal;
            };

            StateChanged += (s, e) =>
            {
                if (WindowState == WindowState.Minimized && OtherSettings.MinimizeToSysTray)
                {
                    Hide();
                    SystemTray.Visible = true;
                }
            };
            #endregion

            #region KeyHook
            KeyHook = new KeyboardHookList(this);

            KeyHook.Register(KeyCode.R, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt,
                             () => Dispatcher.Invoke(() => ToggleRecorderState()));

            KeyHook.Register(KeyCode.S, ModifierKeyCodes.Control | ModifierKeyCodes.Shift | ModifierKeyCodes.Alt,
                             () => Dispatcher.Invoke(() => CaptureScreenShot()));
            #endregion

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(OutPath.Text))
            {
                OutPath.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\");
            }
            // Create the Output Directory if it does not exist
            if (!Directory.Exists(OutPath.Text))
            {
                Directory.CreateDirectory(OutPath.Text);
            }
            Settings.Default.OutputPath = OutPath.Text;
            Settings.Default.Save();

            Closed += (s, e) => Application.Current.Shutdown();

            cursor = new MouseCursor(OtherSettings.IncludeCursor);
            OtherSettings.Instance.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "_IncludeCursor")
                {
                    cursor.Include = OtherSettings.IncludeCursor;
                }
            };
        }