public NotifyIconMenuItem(string text, ref NotifyIconMenuItem menuItem) { this.Text = text; menuItem.MenuItems.Add(this); }
public MainWindow() { InitializeComponent(); // Initializing MainWindow this.Title = "Deviant Dock"; this.Width = 450; this.Height = 300; this.Left = SystemParameters.PrimaryScreenWidth - (this.Width + 20); this.Top = SystemParameters.PrimaryScreenHeight - (this.Height + STANDARD_TASKBAR_HEIGHT); this.Topmost = true; this.WindowStyle = WindowStyle.None; try { this.Icon = BitmapFrame.Create(new Uri("Contents/Icon/icon.ico", UriKind.RelativeOrAbsolute)); } catch (Exception) { // Do nothing } GlassEffect.SetIsEnabled(element: this, value: true); // Initialing notifyIconContextMenu notifyIconContextMenu = new System.Windows.Forms.ContextMenu(); // Initialize NotifyIconMenuItems restoreNotifyIconMenuItem = new NotifyIconMenuItem(text: "Restore", contextMenu: ref notifyIconContextMenu); exitNotifyIconMenuItem = new NotifyIconMenuItem(text: "Exit", contextMenu: ref notifyIconContextMenu); notifyIconContextMenu.MenuItems.Add("-"); helpNotifyIconMenuItem = new NotifyIconMenuItem(text: "Help", contextMenu: ref notifyIconContextMenu); contentsNotifyIconMenuItem = new NotifyIconMenuItem(text: "Contents", menuItem: ref helpNotifyIconMenuItem); aboutNotifyIconMenuItem = new NotifyIconMenuItem(text: "About", menuItem: ref helpNotifyIconMenuItem); // Creating the NotifyIcon notifyIcon = new NotifyIcon(); notifyIcon.Text = "Deviant Dock"; // The Text property sets the text that will be displayed, in a tooltip, when the mouse hovers over the systray icon. notifyIcon.ContextMenu = notifyIconContextMenu; // The ContextMenu property sets the menu that will appear when the systray icon is right clicked. try { notifyIcon.Icon = new Icon("Contents/Icon/icon.ico"); // The Icon property sets the icon that will appear in the systray for this application. } catch (Exception) { // Do nothing } Canvas deviantDockMainCanvas = new Canvas(); minimizeImage = new CustomImage(imageName: "Contents/Images/control_button/button_min_regular.png", width: 24, height: 18); closeImage = new CustomImage(imageName: "Contents/Images/control_button/button_close_regular.png", width: 43, height: 18); minimizeImage.Margin = new Thickness((this.Width - (minimizeImage.Width + closeImage.Width + 15)), 0, 0, 0); minimizeImage.ToolTip = "Minimize"; closeImage.Margin = new Thickness(this.Width - (closeImage.Width + 15), 0, 0, 0); closeImage.ToolTip = "Close to system tray"; dockItemListView = new ListView(); dockItemListView.Margin = new Thickness(10, 40, 0, 0); dockItemListView.Width = this.Width - ((2 * 20) - 5); dockItemListView.Height = this.Height - (this.Height / 3); dockItemListView.Opacity = 0.70; dockyListViewItem = new DockListViewItem(title: "Docky", versionNo: "1.0", description: "A simple dock", imageLocation: "Contents/Images/application_image/icon.png"); ringyListViewItem = new DockListViewItem(title: "Ringy", versionNo: "1.0", description: "Circle shaped\ndock", imageLocation: "Contents/Images/application_image/icon.png"); exitButton = new CustomButton(buttonContent: "Exit", width: 65, height: 25, thickness: new Thickness(dockItemListView.Width - 55, dockItemListView.Height + 55, 0, 0)); helpButton = new CustomButton(buttonContent: "Help", width: (int)exitButton.Width, height: (int)exitButton.Height, thickness: new Thickness(dockItemListView.Width - (55 + 5 + exitButton.Width), dockItemListView.Height + 55, 0, 0)); // Adding Contents this.Content = deviantDockMainCanvas; deviantDockMainCanvas.Children.Add(new CustomImage(imageName: "Contents/Images/application_image/icon.png", width: 16, height: 16)); deviantDockMainCanvas.Children.Add(new TextBlock() { Text = this.Title, Margin = new Thickness(16 + 5, 0, 0, 0) }); deviantDockMainCanvas.Children.Add(minimizeImage); deviantDockMainCanvas.Children.Add(closeImage); deviantDockMainCanvas.Children.Add(dockItemListView); dockItemListView.Items.Add(dockyListViewItem); dockItemListView.Items.Add(ringyListViewItem); deviantDockMainCanvas.Children.Add(exitButton); deviantDockMainCanvas.Children.Add(helpButton); // Adding Event Handler this.MouseLeftButtonDown += new MouseButtonEventHandler(MainWindow_MouseLeftButtonDown); restoreNotifyIconMenuItem.Click += new EventHandler(restoreNotifyIconMenuItem_Click); exitNotifyIconMenuItem.Click += new EventHandler(exitNotifyIconMenuItem_Click); minimizeImage.MouseLeftButtonDown += new MouseButtonEventHandler(minimizeImage_MouseLeftButtonDown); closeImage.MouseLeftButtonDown += new MouseButtonEventHandler(closeImage_MouseLeftButtonDown); dockyListViewItem.addButton.Click += new RoutedEventHandler(dockyListViewItem_addButton_Click); dockyListViewItem.removeButton.Click += new RoutedEventHandler(dockyListViewItem_removeButton_Click); ringyListViewItem.addButton.Click += new RoutedEventHandler(ringyListViewItem_addButton_Click); ringyListViewItem.removeButton.Click += new RoutedEventHandler(ringyListViewItem_removeButton_Click); exitButton.Click += new RoutedEventHandler(exitButton_Click); helpButton.Click += new RoutedEventHandler(helpButton_Click); contentsNotifyIconMenuItem.Click += new EventHandler(contentsNotifyIconMenuItem_Click); aboutNotifyIconMenuItem.Click += new EventHandler(aboutNotifyIconMenuItem_Click); // Initializing Application Settings closeToSystemTray(); if (!File.Exists(path: settingsPath + "PrimarySettings.dds")) { createNewPrimarySettings(); } loadPrimarySettings(); loadDocky(); loadRingy(); }