1

I created a movable panel in WinForms. I use a ToolStrip as a titlebar in the panel. I'll use the ToolStrip to move the panel as well as indicating the panel is "active" or not. So when the panel is active, I want to change the ToolStrip's BackColor to Red.

UPDATE: The panel will host other controls, such as a listview. I want the panel being shown as "active" when the hosted control get focus, kind like the behavior of a normal window, whereas the window becomes the panel, and the titlebar becomes the ToolStrip.

When the panel is considered as "active"

  1. hosted control get focus
  2. ToolStrip being MouseDown/MouseClick
  3. ToolStrip being dragged by mouse

The idea is capturing ToolStrip's Enter/Leave event to change the color, but it seems those events are never fired.

Are those events truly never fired? Should I capture other events?

AZ.
  • 7,333
  • 6
  • 44
  • 62

1 Answers1

0

mmmm there are a few ways to do this I guess.

You could use hook into the IMessageFilter message and see if its over your toolstrip/panel and then act accordingly (WM_LBUTTONDOWN, WM_MOUSEMOVE, WM_LBUTTONUP etc - see windows documentation on WIndows Messages for hex message codes for all windows messages). There are many examples about - for example: How to detect if the mouse is inside the whole form and child controls?

Setting a boolen based on whether active or not, an override in the paint can allow the colour settings - or simply flip them along with/instead of the boolean. Same for moving, set a boolean for move active/or not - and then allow WM_MOUSEMOVE to move the form/panel (or not) as needed.

Community
  • 1
  • 1
Wolf5370
  • 1,374
  • 11
  • 12
  • How can i get (keyboard event) KeyDown or KeyUp or KeyPress event in ToolStripMenuItem.. Even GotFoucs is better... Is there any way to chech if user Using arrow keys Focus or Enter a ToolStripMenuItem ?? – Er Mayank May 28 '15 at 19:22