[英]How to show underscore (shortcut) without holding Alt?
我用ContextMenuStrip創建了一個表單。 我按照以下方式使用文本字段設置其快捷方式:“&File”。 但是,當我通過鼠標右鍵單擊打開此上下文菜單時,僅當我同時按住Alt按鈕時才會顯示下划線。 有沒有辦法在沒有按住Alt按鈕的情況下單擊鼠標顯示下划線?
您可以通過自定義ToolStripSystemRenderer
修改文本呈現行為( HidePrefix
):
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
contextMenuStrip1.Renderer = new AccessKeyMenuStripRenderer();
}
private void Form1_Click(object sender, EventArgs e)
{
contextMenuStrip1.Show(Cursor.Position);
}
}
class AccessKeyMenuStripRenderer : ToolStripSystemRenderer
{
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
{
e.TextFormat &= ~TextFormatFlags.HidePrefix;
base.OnRenderItemText(e);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.