2

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?

Arvo Bowen
  • 4,524
  • 6
  • 51
  • 109
  • Use its MouseEnter and MouseLeave event. Change the Cursor property of the StatusStrip in your event handlers. – Hans Passant Jul 13 '16 at 14:47
  • That's just it. When I click on the `StatusStrip` and look at properties I do not see any property such as `Cursor` – Arvo Bowen Jul 13 '16 at 14:54
  • 1
    Of the **StatusStrip**, not the label. It requires code. – Hans Passant Jul 13 '16 at 14:59
  • Ahh ok got it! I was not aware that it just was not exposed in the `StatusStrip` properties during design-time. Thanks Hans. Also, can you add that as an answer please? You are notorious for answering in a comment and not an actual answer. :P - You probably do it so that you don't get a million notifications. :) – Arvo Bowen Jul 13 '16 at 15:12
  • You have everything you need to know to answer the question yourself. – Hans Passant Jul 13 '16 at 15:16
  • Have you ever tried using `ToolStripControlHost` to host a `LinkLabel` or other controls in a `ToolStrip` or `StatusStrip`? It's really a good option. – Reza Aghaei Jul 13 '16 at 21:20
  • @ArvoBowen Hosting a `Label` or `LinkLabel` in a `ToolStripControlHost` is really a useful option which allows you to set the cursor or other properties. In fact I believe it's really more effective than handling mouse events and changing the cursor. – Reza Aghaei Jul 14 '16 at 16:04
  • Would you mind your actual requirement? What cursor do you need? Do you set `IsLink` property to true? – Reza Aghaei Jul 14 '16 at 19:34
  • @RezaAghaei Your answer that gave an additional method that you deleted was a nice answer and great extra info but a lot more than what I was asking for. The simplest and correct answer is the one I provided below based off of Hans comment. The only reason it's not checked yet is because of stackoverflow's restrictions on how long I have to wait to mark it as the answer. You should add your answer back for possible upvotes in the future. Thanks – Arvo Bowen Jul 14 '16 at 23:39
  • Thank you for your response :) I liked your post and maybe your post is the best fit for the question. But the ability to adding a normal `Label` to the strip is also a good alternative and it's just 2 lines of code. – Reza Aghaei Jul 14 '16 at 23:53
  • By the way, while you can accept only one answer, you can upvote as many answers as you find useful. Did you know it? In fact, upvotes are for saying that an answer is useful. It makes the answers more useful for future readers. Also it motivates users to post good answers :) – Reza Aghaei Jul 14 '16 at 23:56
  • Yea, and I was going to upvote yours as soon as I could accept mine. ~14 hours ;) – Arvo Bowen Jul 14 '16 at 23:59
  • OK, I'll undelete it. Hope it helps you and future readers :) – Reza Aghaei Jul 15 '16 at 00:02
  • What a forgotten question and answers ;) – Reza Aghaei Jul 20 '16 at 21:19

3 Answers3

3

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Arvo Bowen
  • 4,524
  • 6
  • 51
  • 109
1

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);
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
-1

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;
}
jetstream96
  • 144
  • 4
  • 11