I am new to C# I manually populate a context menu with a item click event populated from a listbox of video files located on my drive. The click events fires as expected but repeats 4 times? I only want it to go to the click event once.
Populate menu using listbox code. When a menu item is in mouse hover it creates and populate a menu with a item click event as shown below. The issue is once I click a menu item it goes back to the item click event 4 times on a single click.Being as I am converting mp4 to mp3 files it is very time consuming is there a way I can stop it from running the click event multiple time I tried using a bool statement I even tried making the click event wait using async void. Any help would be appreciated. Thanks in advance.
- private void CsConvertMP4ToMP3_Hover(object sender, EventArgs e)
- {
-
- CSselectVideoFile.DropDownItems.Clear();
-
- foreach (String Item in lstVideoFiles.Items)
- {
- CSselectVideoFile.DropDownItems.Add(Item);
- foreach (ToolStripItem mnuitem in CSselectVideoFile.DropDownItems)
- {
-
- mnuitem.Click += new EventHandler(item_Click);
- }
- }
- }
-
- void item_Click(object sender, EventArgs e)
- {
- ToolStripItem clickedItem = sender as ToolStripItem;
- ConvertVideoToMP3(MP4Name);
- }