contextmenustrip

Change space between Image and Text in ContextMenuStrip

ⅰ亾dé卋堺 提交于 2021-02-10 12:43:27
问题 In my application, I have a ContextMenuStrip with two items. Each item has an image and a text. There's a default gap between the Image section of the Menu Items and their text, as shown in the image below (the gap is indicated by red arrows). I want to reduce the horizontal gap by moving the text towards the left, so that the gap is reduced to a maximum of 1 pixel. Is it possible? If yes how can I? 回答1: A sample setup that shows how to handle a generic ToolStripProfessionalRenderer and a

C# File Copy and Paste

社会主义新天地 提交于 2021-01-29 19:19:02
问题 I am currently working with Copy and Paste with Item (file name) in Listbox. There's no error but copy and paste seems to not be working. I am new to this so I don't know what is the problem here, any help would be appreciated. Code in Copy if(lvwExplorer.SelectedItems[0].Text != "" && lvwExplorer.SelectedItems.Count == 1) { Clipboard.SetText(lvwExplorer.SelectedItems[0].Text); } else { MessageBox.Show("You can only copy one element at a time.", "Cannot Copy", MessageBoxButtons.OK,

C#:使用快捷菜单(ContextMenuStrip)删除DataGridView控件指定行

三世轮回 提交于 2020-03-25 14:33:23
3 月,跳不动了?>>> 工作中遇到一个场景:在DataGridView上单击鼠标右键弹出快捷菜单,在快捷菜单内需要有“删除本行”、“清空数据”等按钮,于是我就自己实现了一个: 实现步骤如下: 步骤1,建立一个C#下的Windows窗体应用程序,取名DgvMenuStripTest 步骤2,主窗体内的控件只有一个名为dgvTest的DataGridView,对这个DataGridView启用添加、启用编辑、启用删除,并设置其在父容器中停靠 步骤3,为这个DataGridView添加MouseClick事件,代码如下: /// <summary> /// DataGridView鼠标单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvTest_MouseClick(object sender, MouseEventArgs e) { //当前操作的DataGridView DataGridView dgv = sender as DataGridView; //当前鼠标位置的行列信息 int col = dgv.HitTest(e.X, e.Y).ColumnIndex; int row = dgv.HitTest(e.X, e.Y)

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

帅比萌擦擦* 提交于 2020-01-13 13:04:34
问题 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;

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

拜拜、爱过 提交于 2020-01-13 13:01:33
问题 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;

Listview Large Icon right click to open ContextMenuStrip

风格不统一 提交于 2020-01-06 03:56:03
问题 In my project I have a ListView and I would like to open my ContextMenuStrip when I clicked right button in the large icon. I tried many things but I am unsuccessful. When I right click inside of ListView the ContextMenuStrip opens, but I want to see just when I right clicked the large icon. Also I need to help about get the clicked icon's name (properties). 回答1: This is a quick and dirty solution; please do put more work into it than I did.. // a class level reference, prepare it where you

How do you get the control that was clicked to open a ContextMenuStrip?

时间秒杀一切 提交于 2019-12-29 06:13:46
问题 I'm using a ContextMenuStrip for multiple controls and I'm trying to figure out the best way to get the control that was actually clicked on to open the Context Menu. The sender just gives the ToolStripMenuItem reference, which has an Owner property that references the ContextMenuStrip , but I cannot figure out how to tell which control the click came from. There must be a simple way to check this, right? I'm checking it in the ToolStripMenuItem 's click event. Friend WithEvents mnuWebCopy As

get contextmenustrip from toolstripmenuitem

允我心安 提交于 2019-12-24 18:58:43
问题 Do I use the Owner , OwnerItem , or the Container property? What if the ToolStripMenuItem is a member of another tsmi, which in turn is a member of another tsmi, etc.? The purpose of this is to be able to add an event handler that gets at the TreeView that has the ContextMenuStrip that has that ToolStripMenuItem . Abstracting a bit, is there a general way to get at the owners of controls, until you reach the one you're interested in? Just cast and hope? 回答1: use ToolStripMenuItem1

Erratic behavior from ContextMenuStrip

回眸只為那壹抹淺笑 提交于 2019-12-24 02:09:56
问题 I am getting some erratic behavior from a ContextMenuStip : private void lstModules_MouseMove(object sender , MouseEventArgs e) { mouse = e.Location; } private void lstModules_MouseDown(object sender , MouseEventArgs e) { ListViewItem item = null; if((hitTest = lstModules.HitTest(mouse)) != null) item = hitTest.Item; switch (e.Button) { case MouseButtons.Right: if (item != null) { // valid item selection ShowModuleDetails(item.Name); lstModules.ContextMenuStrip = mnuContext_Module; } else { /

Get the SourceControl of a DropDownMenu

可紊 提交于 2019-12-17 21:32:58
问题 I have two click events of menu items in a ContextMenuStrip. I can get the SourceControl of the clicked context menu item by doing this code: Control c = ((sender as ToolStripItem).Owner as ContextMenuStrip).SourceControl; But when I use this code on a context menu item that is in another level it, returns null. How can I get the SourceControl in the click event of the second screenshot's menu item? 回答1: The ContextMenuStrip SourceControl (the reference of the current Control where the