Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Forcing MouseDevice to be pressed

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!

like image 359
mmod Avatar asked Oct 28 '10 17:10

mmod


1 Answers

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

like image 70
Ben Gribaudo Avatar answered Oct 25 '22 00:10

Ben Gribaudo