【问题标题】:Setting the type of cursor on a ToolStripStatusLabel object在 ToolStripStatusLabel 对象上设置光标类型
【发布时间】:2016-07-13 14:38:49
【问题描述】:

我的表单底部有一个StatusStrip 对象,其中添加了一个ToolStripStatusLabel 对象。我想更改鼠标悬停在鼠标光标上时显示的类型。

我怎样才能做到这一点?

【问题讨论】:

  • 使用它的 MouseEnter 和 MouseLeave 事件。在事件处理程序中更改 StatusStrip 的 Cursor 属性。
  • 就是这样。当我单击StatusStrip 并查看属性时,我看不到任何属性,例如Cursor
  • 属于 StatusStrip,而不是标签。它需要代码。
  • 啊,好的,明白了!我不知道它只是在设计时没有暴露在StatusStrip 属性中。谢谢汉斯。另外,您可以将其添加为答案吗?您因在评论中回答而不是实际答案而臭名昭著。 :P - 您可能这样做是为了不会收到一百万条通知。 :)
  • 您拥有自己回答问题所需要知道的一切。

标签: c# winforms toolstripstatuslabel


【解决方案1】:

ToolStripStatusLabel 对象没有Cursor 属性。要更改显示的光标,您必须在运行时设置 StatusStrip.Cursor 属性。

使用标签的 MouseEnter 和 MouseLeave 事件更改 StatusStrip.Cursor 属性。

【讨论】:

    【解决方案2】:

    作为替代方案,您可以在ToolStripControlHost 中托管Label 并将其添加到StatusStrip。这样您就可以设置所有Label 属性,包括Cursor。它会像其他标准物品一样工作。

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

    【讨论】:

      【解决方案3】:

      将以下代码添加到您的表单中。然后在设计器中,将 MouseEnter 的事件处理函数设置为 SetHandCursor,将 MouseLeave 设置为 SetDefaultCursor。

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

      【讨论】:

        猜你喜欢
        • 2014-12-07
        • 2010-09-25
        • 2023-04-10
        • 1970-01-01
        • 2013-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-06
        相关资源
        最近更新 更多