Setting the type of cursor on a ToolStripStatusLabel object

梦想的初衷 提交于 2019-12-24 17:19:09

问题


I have a StatusStrip object at the bottom of my form with a ToolStripStatusLabel object added to it. I want to change the type of mouse cursor that is displayed when one hovers over it.

How can I achieve this?


回答1:


The ToolStripStatusLabel object does not have a Cursor property. In order to change the displayed cursor you must set the StatusStrip.Cursor property at run-time.

Use the label's MouseEnter and MouseLeave event to change the StatusStrip.Cursor property.




回答2:


As an alternative, you can host a Label in ToolStripControlHost and add it to StatusStrip. This way you can set all Label properties including Cursor. It will act like other standard items.

var item = new ToolStripControlHost(new Label {Text= "Some Text", Cursor= Cursors.Hand});
this.statusStrip1.Items.Add(item);



回答3:


Add the following code to your form. Then in the designer, set the event handler of MouseEnter to SetHandCursor, and MouseLeave to SetDefaultCursor.

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

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


来源:https://stackoverflow.com/questions/38354766/setting-the-type-of-cursor-on-a-toolstripstatuslabel-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!