void ElementClickedEH(object sender, EventArgs e) { ContextMenuStrip popup = new ContextMenuStrip(); popup.AutoSize = true; ToolStripDropDownButton changeTo = new ToolStripDropDownButton("Change to..."); AdjustDropDownSize(popup, changeTo); changeTo.DropDown = new ToolStripDropDown(); changeTo.DropDown.Items.Add("Empty", null, new EventHandler(ChangeToEmptyEH)); changeTo.DropDown.Items.Add("Definition", null, new EventHandler(ChangeToDefinitionEH)); popup.Items.Add(changeTo); popup.Items.Add("Assign letter", null, new EventHandler(AssignLetterEH)); if (letter.Length > 0) //If a letter has been assigned, show this menu. { ToolStripButton definiteButton = new ToolStripButton("Definite", null, new EventHandler(DefiniteClickedEH)); definiteButton.Checked = fDefinite; popup.Items.Add(definiteButton); } popup.Opacity = 0.5; popup.PerformLayout(); popup.Show(_wControl, new Point(_wControl.Width, _wControl.Height)); popup.Update(); }
private ContextMenuStrip?BuildContextMenuStrip() { var contextMenuStrip = new ContextMenuStrip { ImageList = _imageList }; contextMenuStrip.Closed += (o, e) => { if (ReferenceEquals(_notifyIcon.ContextMenuStrip, o)) { _notifyIcon.ContextMenuStrip = null; } }; contextMenuStrip.ItemClicked += (o, e) => { if (e.ClickedItem.Tag is Action act) { act.Invoke(); } }; var items = BuildMenuItems(); if (items is null || !items.Any()) { contextMenuStrip.Dispose(); return(null); } contextMenuStrip.Items.AddRange(items); contextMenuStrip.PerformLayout(); return(contextMenuStrip); }
/// ------------------------------------------------------------------------------------ protected virtual void HandleColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.ColumnIndex != Index) { return; } _grid.Stop(); var audioCol = _grid.Columns.Cast <DataGridViewColumn>().FirstOrDefault(c => c is AudioWaveFormColumn); if (audioCol != null) { _grid.InvalidateCell(audioCol.Index, _grid.CurrentCellAddress.Y); } foreach (var menuItem in _columnMenu.Items.OfType <ToolStripMenuItem>().Where(m => m.Tag is AudioRecordingType)) { menuItem.Checked = ((AudioRecordingType)menuItem.Tag == PlaybackType); } _columnMenu.PerformLayout(); var rc = _grid.GetCellDisplayRectangle(Index, -1, false); var pt = _grid.PointToScreen(new Point(rc.Right - _columnMenu.Width, rc.Bottom)); _columnMenu.Show(pt); }
protected override ContextMenuStrip CreateMenu() { var menu = new ContextMenuStrip { AutoSize = true, ImageScalingSize = new Size(16, 16) }; // Create a 'count lines' item. var itemUpload = new ToolStripMenuItem("Upload file to fritzen.xyz") { AutoSize = true, ImageScaling = ToolStripItemImageScaling.SizeToFit, Image = icon }; itemUpload.Click += ItemUpload_Click; // Add the item to the context menu. menu.Items.Add(itemUpload); menu.PerformLayout(); // Return the menu. return(menu); }
private static void CalculateOverflow(ContextMenuStrip contextMenu, ToolStripItemCollection items, int maxHeight) { int height = contextMenu.Padding.Top; contextMenu.PerformLayout(); int totalItems = items.Count; int overflowIndex = 0; bool overflowNeeded = false; // only examine up to last but one item. for (; overflowIndex < totalItems - 2; ++overflowIndex) { ToolStripItem current = items[overflowIndex]; ToolStripItem next = items[overflowIndex + 1]; if (!current.Available) { continue; } height += GetTotalHeight(current); if (height + GetTotalHeight(next) + contextMenu.Padding.Bottom > maxHeight) { overflowNeeded = true; break; } } if (overflowNeeded) { // Don't dispose overflow here because that will prevent it from working. ToolStripMenuItem overflow = new ToolStripMenuItem(FwCoreDlgControls.kstid_More, Images.arrowright); overflow.ImageScaling = ToolStripItemImageScaling.None; overflow.ImageAlign = ContentAlignment.MiddleCenter; overflow.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; for (int i = totalItems - 1; i >= overflowIndex; i--) { ToolStripItem item = items[i]; items.RemoveAt(i); overflow.DropDown.Items.Insert(0, item); } CalculateOverflow(contextMenu, overflow.DropDownItems, maxHeight); if (overflow.DropDown.Items.Count > 0) { items.Add(overflow); } else { overflow.Dispose(); } } }
private void BuildMainMenu() { notifyIcon.ContextMenuStrip = refreshingMenu; mainMenu.Items.Clear(); dynamicMenuItems.Clear(); registry.Refresh(); BuildDynamicItems(clean: true); ToolStripMenuItem allGamesItem; if (registry.InstalledGames.Count != 0) { allGamesItem = AddToolStripMenuItem(mainMenu.Items, "All installed games"); allGamesItem.DropDown.ItemClicked += OnContextMenuItemClicked; allGamesItem.DropDown.Closing += OnContextMenuClosing; allGamesMenuItems = allGamesItem.DropDownItems; _ = AddGameMenuItems(allGamesMenuItems, registry.InstalledGames).ToList(); } else { allGamesItem = AddToolStripMenuItem(mainMenu.Items, "No games installed"); allGamesItem.Enabled = false; } AddMenuSeparator(mainMenu.Items); AddToolStripMenuItem(mainMenu.Items, "Refresh", OnRefreshClicked); AddExitMenuItem(mainMenu.Items); ApplyProperties(mainMenu); mainMenu.PerformLayout(); if (mainMenuWidth < mainMenu.Width) { mainMenuWidth = mainMenu.Width; } notifyIcon.ContextMenuStrip = mainMenu; }
void ElementClickedEH(object sender, EventArgs e) { ContextMenuStrip popup = new ContextMenuStrip(); popup.AutoSize = true; ToolStripDropDownButton changeTo = new ToolStripDropDownButton("Change to..."); AdjustDropDownSize(popup, changeTo); changeTo.DropDown = new ToolStripDropDown(); changeTo.DropDown.Items.Add("Letter", null, new EventHandler(ChangeToLetterEH)); changeTo.DropDown.Items.Add("Definition", null, new EventHandler(ChangeToDefinitionEH)); popup.Items.Add(changeTo); popup.Opacity = 0.5; popup.PerformLayout(); popup.Show(_wControl, new Point(_wControl.Width, _wControl.Height)); popup.Update(); }
//handler for showing hover information private void FieldButton_MouseHover(object sender, EventArgs e) { if (status == FIELDSTATUS.NORMAL) //if nothing special is active, display information about the field while hovering { infoMenu.Hide(); infoMenu.Items.Clear(); string info = ""; info += getUnitNameAt(((FieldButton)sender).x, ((FieldButton)sender).y); //add unit handler if (info != "") { populateUnitMenu(ref mainBoard.getField(((FieldButton)sender).x, ((FieldButton)sender).y).unit); unitMenuStrip.Text = info; infoMenu.Items.Add(unitMenuStrip); info = ""; } info += getBuildingNameAt(((FieldButton)sender).x, ((FieldButton)sender).y); //add building handler if (info != "") { populateBuildingMenu(ref mainBoard.getField(((FieldButton)sender).x, ((FieldButton)sender).y).building); buildingMenuStrip.Text = info; infoMenu.Items.Add(buildingMenuStrip); info = ""; } info = ((FieldButton)sender).x + ":" + ((FieldButton)sender).y; infoMenu.Name = info; infoMenu.Show(new Point(((FieldButton)sender).drawCenterX, ((FieldButton)sender).drawCenterY)); infoMenu.PerformLayout(); } else if (status == FIELDSTATUS.BUILDING || status == FIELDSTATUS.RECRUITING) //if player wants to build, highlight field with hoverForm { int borderWidth = (this.Width - this.ClientSize.Width) / 2; int titleBarHeight = this.Height - this.ClientSize.Height - borderWidth; hoverForm.setShape(((FieldButton)sender).getShape()); Point hoverPoint = this.Location; hoverPoint.Offset(new Point(((FieldButton)sender).drawX + borderWidth, ((FieldButton)sender).drawY + titleBarHeight)); hoverForm.setUp((((FieldButton)sender).x + ((FieldButton)sender).y) % 2 == 0); hoverForm.updateLocation(hoverPoint); hoverPosition[0] = ((FieldButton)sender).x; hoverPosition[1] = ((FieldButton)sender).y; } }
/// <summary> /// /// Thread save call by invoking if necessary /// </summary> private void SetCallCurrentNumberMenuItem() { if (_contextMenuStrip.InvokeRequired) { SetCallCurrentNumberMenuItemCallback d = new SetCallCurrentNumberMenuItemCallback(SetCallCurrentNumberMenuItem); _contextMenuStrip.Invoke(d); } else { _callCurrentNumberMenuItem.Text = MessageHelper.CallCurrentNumberText; if (_callCurrentNumberMenuItem.Text == "") { _callCurrentNumberMenuItem.Available = false; } else { _callCurrentNumberMenuItem.Available = true; _contextMenuStrip.PerformLayout(); } } }