BorderlessGaming.Forms.MainWindow.processContext_Opening C# (CSharp) Method

processContext_Opening() private method

Sets up the Process-ContextMenu according to the current state
private processContext_Opening ( object sender, CancelEventArgs e ) : void
sender object
e CancelEventArgs
return void
        private void processContext_Opening(object sender, CancelEventArgs e)
        {
            if (this.lstProcesses.SelectedItem == null)
            {
                e.Cancel = true;
                return;
            }

            ProcessDetails pd = ((ProcessDetails)this.lstProcesses.SelectedItem);

            if (!pd.Manageable)
            {
                e.Cancel = true;
                return;
            }

			this.contextAddToFavs.Enabled = controller.Favorites.CanAdd(pd.BinaryName) && controller.Favorites.CanAdd(pd.WindowTitle);

            if (Screen.AllScreens.Length < 2)
            {
                this.contextBorderlessOn.Visible = false;
            }
            else
            {
                this.contextBorderlessOn.Visible = true;

                if (this.contextBorderlessOn.HasDropDownItems)
                    this.contextBorderlessOn.DropDownItems.Clear();

                Rectangle superSize = Screen.PrimaryScreen.Bounds;

                foreach (Screen screen in Screen.AllScreens)
                {
                    superSize = Tools.GetContainingRectangle(superSize, screen.Bounds);

                    // fix for a .net-bug on Windows XP
                    int idx = screen.DeviceName.IndexOf('\0');
                    string fixedDeviceName = (idx > 0) ? screen.DeviceName.Substring(0, idx) : screen.DeviceName;

                    string label = fixedDeviceName + ((screen.Primary) ? " (P)" : string.Empty);

                    ToolStripMenuItem tsi = new ToolStripMenuItem(label);
					tsi.Click += (s, ea) => { this.controller.RemoveBorder_ToSpecificScreen(pd, screen); };

                    this.contextBorderlessOn.DropDownItems.Add(tsi);
                }

                // add supersize Option
                ToolStripMenuItem superSizeItem = new ToolStripMenuItem("SuperSize!");

				superSizeItem.Click += (s, ea) => { this.controller.RemoveBorder_ToSpecificRect(pd, superSize); };

                this.contextBorderlessOn.DropDownItems.Add(superSizeItem);
            }
        }
        
MainWindow