我想在用户光标悬停在特定的ToolStripButton上时更改用户的光标,而不是用于ToolStrip上的其他项目.如何设置按钮的光标?
因为ToolStripItem不从Control继承,所以它没有Cursor属性.
您可以在MouseEnter事件上设置表单光标,并在MouseLeave事件上恢复表单光标,VB示例如下:
Dim savedCursor As Windows.Forms.Cursor Private Sub ToolStripButton1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton1.MouseEnter If savedCursor Is Nothing Then savedCursor = Me.Cursor Me.Cursor = Cursors.UpArrow End If End Sub Private Sub ToolStripButton1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton1.MouseLeave Me.Cursor = savedCursor savedCursor = Nothing End Sub
更新
以下是C#中的相同答案:
private Cursor savedCursor; private void ToolStripButton1_MouseEnter(object sender, EventArgs e) { if (savedCursor == null) { savedCursor = this.Cursor; this.Cursor = Cursors.UpArrow; } } private void ToolStripButton1_MouseLeave(object sender, EventArgs e) { this.Cursor = savedCursor; savedCursor = null; }