contextmenustrip

ContextMenuStrip text alignment C#

瘦欲@ 提交于 2019-12-13 02:15:18
问题 Hi Does anybody know how we can align the text in the ContextMenuStrip (in WinForms) to the center? thanks! 回答1: Implement custom ToolStripRenderer (use one of 2 standard to minimize code): public sealed class CustomRenderer : ToolStripProfessionalRenderer { protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) { if(e.Item.IsOnDropDown) { e.TextFormat |= TextFormatFlags.HorizontalCenter; } base.OnRenderItemText(e); } } And use it: ToolStripManager.Renderer = new

Find control that caused ContextMenuStrip menu to be shown

无人久伴 提交于 2019-12-13 02:11:57
问题 I've read a few articles on SO: How to detrmine the control that cause ContextMenuStrip Getting the control of a context menu and a couple others that suggested use of the SourceControl property.. but none work in this context: I have a ContextMenuStrip that has a child ToolStripMenuItem - this code from the windows forms designer generated section: // _tileContextMenuStrip // this._tileContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.tileKindToolStripMenuItem,

How to show underscore (shortcut) without holding Alt?

送分小仙女□ 提交于 2019-12-12 16:09:44
问题 I've created a form with ContextMenuStrip. I set its shortcut using Text field in following way: "&File". However, when I open this context menu by right mouse button click, underscore is shown only when I simultaneously hold Alt button. Is there a way to show underscore on a mouse click without holding Alt button? 回答1: You can modify the text rendering behaviour ( HidePrefix ) via a custom ToolStripSystemRenderer : namespace WindowsFormsApplication1 { public partial class Form1 : Form {

Finding the selected item of list view

前提是你 提交于 2019-12-11 05:46:02
问题 I currently have a list view which has several rows of data and I have a contextmenustrip in C# .NET. What I am having problems with is when you click on the menu strip item I want to know which row has been selected. 回答1: To get selected rows as sindre says you do like this: foreach (ListViewItem item in lvFiles.SelectedItems) { .................................... } lvFiles is the ListView. 回答2: To get the selected item of list view, try this: int index = 0; if (this.myListView.SelectedItem

How to Stop DataGridView editing after checked cell?

会有一股神秘感。 提交于 2019-12-11 00:52:33
问题 I use ContexMenuStrip on DataGridView to delete some rows but it doesn't work correctly. Every time if I checked 3 rows, after selecting the ContexMenuStrip it only deletes 2 rows. When I do this code without the ContexMenuStrip (by Button ) that works correctly. When I see the behavior I understand current row is editing but doesn't finish. After double clicking on the current row to stop editing my ContexMenuStrip works correctly. How to stop editing after checking the CheckBox ? 回答1: When

ToolStripMenuItem added to several places?

时间秒杀一切 提交于 2019-12-10 21:33:56
问题 I have a large list of entities which the user needs to be able to select from. I have a ContextMenuStrip on my window, and has a few MenuItems for each category of entity. In a library example, think "Staff", "Borrowables", "Patrons", etc... "Staff" may contain "By Employment Type" -> { "Full Time", "Part Time" } or "By Gender" -> { "Male", "Female" } etc. "Borrowables" may contain "By Type" -> { "Books", "Magazines", "DVDs" } or "By Genre" -> { "Fiction" -> { "Sci-Fi", "Romance", "Crime" },

Source control is null when accessing from a sub context menu item in C#

本秂侑毒 提交于 2019-12-10 15:48:54
问题 I am trying to change the color of a button when they click on a sub menu item (colors > red) from a Context Menu Strip. This code is attached to user defined amount of buttons. To figure out which button they are trying to change, I am trying to go from the sub item to the source control like such: sender > owner tool strip > owner menu > source control. My Code: private void redToolStripMenuItem_Click(object sender, EventArgs e) { ToolStripItem subItem = sender as ToolStripItem; if (subItem

Do not close ContextMenuStrip on selection of certain items

我是研究僧i 提交于 2019-12-08 15:57:42
问题 Is it possible to leave a ContextMenuStrip open after a selection/check of certain items? I plan on using a simple ContextMenuStrip to set a filter (this way i could use the same filter either in a menu or as a right-click option). The menu lists a number of items, and i would like the user to be able to make a selection of the items using the basic Check functionality. Once the selection is done the user can click an Activate filter option or can click outside the menu to either activate or

Deselect ToolStripItem on ContextMenuStrip

六眼飞鱼酱① 提交于 2019-12-08 07:04:38
问题 Simple question: I can .Select a ToolStripItem (like, if i want a preselected option when opening a context menu strip) but i cannot seem to find a way to set .Selected to false or somehow deselect it! Is it possible? 回答1: There is private method ClearAllSelections in ToolStrip class, which removes selections from items. You can invoke it via reflection: MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke

How to identify dataGridView cell that was right clicked on for ContextMenuStrip?

吃可爱长大的小学妹 提交于 2019-12-05 15:13:47
User right clicks on a cell within a DGV, then makes a selection in the ContextMenuStrip. Based on their CMS selection, I want to do something (copy, hide, filter). My problem is identifying the cell that was right clicked on. I was trying to handle this scenario with the following method, but [ColumnIndex] cannot be referenced. private void cmsDataGridView_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.Text) { case "Copy": break; case "Filter On": break; case "Hide Column": DataGridViewBand band = dataGridView1.Columns[e.ColumnIndex]; band.Visible = false;