Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

c# - Windows Forms | MenuStrip Sub-Items (ToolStripMenuItem) changing Cursor won't work

I want to have a Hand Cursor for all ToolStripMenuItems.

So i change it in the MouseEnter and MouseLeave Events with this.Cursor = Cursors.Hand; & this.Cursor = Cursors.Default;. I've disabled latter for debugging purpose, so i can see if it changes at all.

It only works for "Root" Items. Not for their Sub-ToolStripMenuItems. The Events fire, it's just like the Cursor get's overridden by Sub-Items.

Any help would be appreciated, it looks weird with the default Cursor. I am using the latest version of VS 2019 and work with .NET Framework 4.8

Here is a little screen:

Problem Description as Screen

System-Info:

  • Edition: Windows 10 Pro
  • Version: 20H2
  • OS-Build: 19042.746
question from:https://stackoverflow.com/questions/65867656/windows-forms-menustrip-sub-items-toolstripmenuitem-changing-cursor-wont-wo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works fine for me, both for root and sub items:

    private void ...ToolStripMenuItem_MouseMove(object sender, EventArgs e)
    {
        this.Cursor = Cursors.Hand;
    }

    private void ..ToolStripMenuItem_MouseLeave(object sender, EventArgs e)
    {
        this.Cursor = Cursors.Default;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...