コード例 #1
0
        private async void InitializeStartup()
        {
            InitializeLogger();

            App = new DeviceTrackerApp();
            //DeviceTrackerApp.Current.Resources.Add("Locator", new DeviceTracker.ViewModel.ViewModelLocator());
            App.Run();
        }
コード例 #2
0
        public static void Init()
        {
            try
            {
                _notifyIcon = new NotifyIcon()
                {
                    Text = @"Open Device Tracker",
                };

                //Setting Icon
                ToggleNotifyIconStatus();

                /****ToolStripMenuItems and handling****/

                _aboutMenuItem = new ToolStripMenuItem(@"About", null, (sender, args) =>
                {
                    try
                    {
                        System.Windows.MessageBox.Show("Developed and designed by @aneesahammed", "Device Tracker", MessageBoxButton.OK);
                    }
                    catch (Exception ex)
                    {
                    }
                });



                //Exit
                _exitMenuItem = new ToolStripMenuItem(@"Exit", null, (sender, args) =>
                {
                    try
                    {
                        Exit();
                    }
                    catch (Exception ex)
                    {
                    }
                });


                //ContextMenuStrip
                _notifyIcon.ContextMenuStrip = new ContextMenuStrip();
                _notifyIcon.ContextMenuStrip.Items.AddRange(new ToolStripItem[]
                {
                    _aboutMenuItem, _exitMenuItem, //new ToolStripSeparator(),
                });

                //Opening of ContextMenuStrip
                _notifyIcon.ContextMenuStrip.Opening += (sender, args) =>
                {
                    try
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                };

                //Click
                _notifyIcon.Click += (sender, args) =>
                {
                    try
                    {
                        MethodInfo mi = typeof(NotifyIcon).GetMethod(@"ShowContextMenu",
                                                                     BindingFlags.Instance | BindingFlags.NonPublic);
                        mi.Invoke(_notifyIcon, null);
                    }
                    catch (Exception ex)
                    {
                    }
                };

                //DoubleClick
                _notifyIcon.DoubleClick += (sender, args) =>
                {
                    try
                    {
                        DeviceTrackerApp.LaunchMainWindow();
                    }
                    catch (Exception ex)
                    {
                    }
                };

                //setting icon visible
                _notifyIcon.Visible = true;
            }
            catch (Exception)
            {
                throw;
            }
        }