How to trap the mouse events (move, hover, etc) for the designerhost?

I've implemented a custom form designer based on MSKB 04 sample. I'd like to perform some actions when cursor moves over the designer. How can I trap these mouse events Or should I take a different approach for this kind of task


Thanks,
Alan



Answer this question

How to trap the mouse events (move, hover, etc) for the designerhost?

  • bev a

    Martin,

    I finally got a chance to try the behavior following the MSDN examples. However, I'm still baffled how to install gloable behavior. Do you by any chance have a code snippet to demonstrate the usage I didn't find anywhere mentioned how to use the behaviorservice...

    Thanks,
    Alan


  • RLGilby

    Hey Alan,

    Use the BehaviorService to install a global behavior.

    Martin



  • Asim Shah

    Just a quick followup, can the behaviorservice enable the combobox drop down the list (just like in runtime), i.e., enable the mouse-click event

    Thanks,
    Alan


  • dtrenaman

    Martin,

    I din't get a chance to try out the global behavior yet. Thereis a bit learning curve I need to go through on it... Behavior seems to play a big role in design time of 2.0. Thank you again, Martin.

    Alan


  • beckd2

    Thanks a lot to Both!

    Regards


  • Tanvir Huda

    Do any of you perharps have an example of how you trapped the mouse enter, hover event for the designerhost
  • Arnaud H

    Tabas,

    Please follow Martin's code snippet (big thanks, Martin!) to install behavior. In your custom behavior, you could override onmousedown/up to instruct how the combobox behaves. To show a dropdownlist in designtime, you could refer to the below code snippet:

    //relatedControl is passed in from my custom combobox designer
    ComboBox
    cb = this.relatedControl as ComboBox;

    if (cb != null)
    {
    cb.DropDownHeight = 100;
    cb.DroppedDown =
    true;
    cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
    }

    HTH :)

    Alan


  • Amanda Theo

    Hi,

    I am not sure what you mean. If you have a global behavior, you will get OnMouseDown and you can then do whatever you want.

    Martin



  • Marcin Belczewski

    I just want to have a combo box in designtime behaves like in runtime: users could click the arrow on the combo and the list of items will be displayed like in runtime. Is it possible to re-route this mousedown event to the combobox via behaviorservice Or I should tacklt this problem in a different approach

    Alan


  • MariaJeff

    There's a couple of ways you could possibly do it:

    1. You could check in your Behavior's OnMouseDown in the mousedown happened over the arrow on the combobox, and if so send a mouseclick to the combobox. Not sure if that will work.

    2. You could write your own designer for the combobox. Attach a glyph to it (through GetGlyphs on your designer) with a behavior. The behavior associated with the glyph should then get the OnMouseDown. This will help you do the hittesting you would otherwise have to do in #1. Then you would send a mouseclick to the combobox. Again, not sure if it will work. Unfortunately I am a little pressed for time right now. :-) But give it a try.

    The Glyph/Behavior stuff shouldn't take you long.

    Martin



  • Henio

    Hey Alan,

    A global behavior is a behavior that lives on the BehaviorStack. Behaviors on this stack get first crack at messages like mouse events and drag/drop. If you override an event, and do not want to handle it, you should call base. If you don't override an event, the base class will handle calling the next Behavior on the stack for you. This is why it is important that you create your behavior with the callParentBehavior set to true.

    To install a global behavior, you do this:

    BehaviorService svc = GetService(typeof(BehaviorService)) as BehaviorService;

    MyBehavior behavior = new MyBehavior(...)

    if (svc != null) {

    svc.PushBehavior(behavior)

    }

    When you are done with the behavior, you pop it off like this:

    BehaviorService svc = GetService(typeof(BehaviorService)) as BehaviorService;

    if (svc != null) {

    svc.PopBehavior(behavior)

    }

    You can have a global behavior that only exists for a short period of time, like a Resize behavior. Ex: When the Designer detects a gesture that indicates that the user wants to resize a control, we new up a ResizeBehavior, and push it on the stack. When the user is done, we pop it off the stack.

    You can also have a global behavior that is always around. Here you need to find the right time to push it on the stack. The Data Sources window is one such example -- it pushes their global behavior when their VS Package is initialized.

    You probably want to do something similar. As part of your initialization, you will push a global behavior on the stack. You need to do it after the BehaviorService has been installed, which happens in DocumentDesigner.Initialize.

    Martin



  • larsw

    LearnToRock wrote:

    I just want to have a combo box in designtime behaves like in runtime: users could click the arrow on the combo and the list of items will be displayed like in runtime. Is it possible to re-route this mousedown event to the combobox via behaviorservice Or I should tacklt this problem in a different approach

    Alan

    I'm interested in the solution for this question too!. Please, LearnToRock..., place the code here.

    TIA!


  • How to trap the mouse events (move, hover, etc) for the designerhost?