Actually, I want to make a switchable tick in the main menu in the WinForms application. Tell me, is it possible (and if possible, how) to do this with the built-in tools of Visual Studio (2008 edition). To make it clearer, I provide a screenshot of the desired result using the example of the uTorrent program.
1 answer
private void toolStripMenuItem2_Click(object sender, EventArgs e) { if (showIcon == false) { toolStripMenuItem2.Image = Bitmap.FromFile("d:\\pic.bmp");//рисовать галочку showIcon = true; //сделать действие } else { toolStripMenuItem2.Image = null; showIcon = false; //сделать действие } }
pic.bmp (or .ico, .jpg) - a picture with a tick. When you click a menu item, draw a check mark and do some action (for example, change the desired parameter to 1). When you click again, remove the check mark and do another action (for example, change the desired parameter to 0).
"At the request of the workers" instead of the bydlokoderksky option, a kosher version is offered :)
private void toolStripMenuItem2_Click(object sender, EventArgs e) { if (toolStripMenuItem2.CheckState == CheckState.Unchecked) { toolStripMenuItem2.CheckState = CheckState.Checked; } else { toolStripMenuItem2.CheckState = CheckState.Unchecked; } }
- Thank you very much. As expected, you will have to insert a picture. It is a pity that there is no built-in tools for this action. By the way, you can not open the external file with the icon, but simply add it to the resources and then assign it: toolStripMenuItem2.Image = global :: ImyaProekta.Properties.Resources.Image5; - Jembo_by
- one
- Understood, thanks! - Jembo_by
- AlexeyM, thank you, corrected :) - Mikola
|