I have a ToolstripLabel for which I want to set UseMnemonic to false. But it doesn't have this property. Is there a way to do this?
I tried casting it to label, but it didn't work.
You can't get to it. The basic flaw is that the Text of the label is rendered with a TextFormatFlags value that's missing the HidePrefix option. Getting that value changed is not possible, it is buried inside internal code.
A workaround is to use your own renderer and fix the problem by altering the text before it is rendered. Make that look like this:
public Form1() {
InitializeComponent();
toolStrip1.Renderer = new MyRenderer();
}
private class MyRenderer : ToolStripProfessionalRenderer {
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
if (e.Item is ToolStripItem) e.Text = e.Text.Replace("&", "&&");
base.OnRenderItemText(e);
}
}