3

ここにサンプルのC#ウィンドウフォームがあります。マウスを左クリックしたときに通知アイコンのコンテキストメニューを表示する必要があります。必要なコードをどこに書くかを以下のようにマークしました。

private void button1_Click(object sender, EventArgs e)
{
        //Need to show the context menu here
}

助けてください!

4

1 に答える 1

5

アイコンを左クリックしたときにメニューを表示するには

private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu",
            BindingFlags.Instance | BindingFlags.NonPublic);

        methodInfo.Invoke(this.notifyIcon, null);
    }
}

質問のボタンがクリックされたときにメニューを表示するには

private void button1_Click(object sender, EventArgs e)
{
    //Need to show the context menu here
    MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu",
        BindingFlags.Instance | BindingFlags.NonPublic);
    methodInfo.Invoke(this.notifyIcon, null);
}
于 2010-08-23T09:17:13.203 に答える