admin管理员组文章数量:1405624
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.
本文标签: cWinforms cursor updatesStack Overflow
版权声明:本文标题:c# - Winforms cursor updates - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744278161a2598516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论