views:

26

answers:

1

Hi!

I have a windows form in a wpf window, and I'm trying to use DragMove when I click on the windows form, it's a picturebox so I want to be able to drag the window around just by clicking the picture.

I catch my form's mouse down, and raise the wpf window's mouseleftbuttondown event with:

if (e.Button == MouseButtons.Left)
        {
            MouseDevice mouseDev = InputManager.Current.PrimaryMouseDevice;
            MouseButtonEventArgs mouseEvent = new MouseButtonEventArgs(mouseDev, 0, MouseButton.Left)
            {
                RoutedEvent = MouseLeftButtonDownEvent
            };
            RaiseEvent(mouseEvent);
        }

However whenever I check the InputManager.Current.PrimaryMouseDevice from my handler (or my form's MouseMove handler), the LeftButton's state is "released".

Why is this? I can't figure out a way to force it to be "pressed" since all the properties are read-only.

Or is my approach simply wrong and is not possible? I did also try setting the location of my window on mouse move, but some weird stuff happens where my mouse values keep going back to the previous position.

Thanks!

edit: So I'm manually adjusting the window location, but still hope someone can enlighten me as to why MouseDevice doesn't get pressed on a windows form. The "weird stuff happens..." was just a dumb mistake on my part, I kept resetting the mouse coordinates on mouse move, but realized that my mouse never moves relative to the window since the window is moving too, duh!

A: 

Hello,

A similar issue stumped me for a while: the ButtonState property of MouseButtonEventArgs reflects the real-time state of that button, not a state snapshot taken when the event was raised. I wonder if the same holds true re your accessing LeftButton's state.

Hope this helps,
Ben

Ben Gribaudo
Well not quite; since I'm click+dragging, the live state should still be "pressed" when the MouseDown event is hit, however it isn't pressed. Perhaps it has to do with windows forms. When I click outside of my form, it tells me the mouse is pressed, however if I click inside of the form, it doesn't.
mmod