最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Winforms cursor updates - Stack Overflow

programmeradmin5浏览0评论

On my form, I have a PictureBox, and on it I have a panel that contains a button. What I am trying to achieve is to change the cursor on the PictureBox from an arrow to a hand when the button is pressed, but I do not want the cursor of the panel to change.

I though this would be easy so I wrote this code:

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

The whole code for this method is:

    private void btnCrimson_Click(object sender, EventArgs e)
    {
        // Clear Selected layer
        selectedLayer.Clear();
        DeselectLstView();

        // Select or deselect the colour
        if (paintSelected && penPaint.Color == Color.Crimson)
        {
            paintSelected = false;
            picBxMain.Cursor = Cursors.Hand;
        }
        else
        {
            paintSelected = true;
            picBxMain.Cursor = Cursors.Arrow;
        }

        penPaint.Color = Color.Crimson;

        tblLayoutPnlCtrlContainer.Enabled = true;

        // Reset Colour Image
        colourLayer.Clear();

        // Arguments must be in the order that they are layered
        compositeImage.ComposeLayers(new List<clsBitmapGraphics> { baseLayer, trackLayer });
        picBxMain.Image = RefreshDisplay(compositeImage.Image);
        picBxMain.Refresh();
    }

In which I am changing the cursor type whenever the paining tool is selected or deselected.

However, when I press the button, the cursor on the panel temporarily changes to a hand before returning to the default cursor.

I have already spent a long time looking on the internet for solution and all I've found is this:

Application.DoEvents();

Which does work, but instead of the cursor flickering between a hand and a arrow, it makes all the other buttons in the panel flicker when they are redrawn.

Any help appreciated.

EDIT: initially the panel containing the button and the PictureBox were in the same container. I though this might be a problem so I moved the panel out and placed it on top. This did nothing to solve the problem.

发布评论

评论列表(0)

  1. 暂无评论