Enable press and hold for right-clicking with - c#

I'm working with a WPF application.This application runs on a pc with a touch screen and when I push one button for more than 3 seconds MyButton_PreviewMouseUp event occurs and after that occurs a MyButtonSimple_PreviewMouseRightButtonDown event. I need to disable something for disabling the function of windows that do this.

You are not describing the default behaviour of a Button. In a normal WPF application, the PreviewMouseUp event occurs only when a pressed mouse button is let go. You can easily prove this yourself by adding a Button to a new WPF application and attaching a handler to the PreviewMouseUp event. You will see that it is only raised when you lift your finger off a pressed mouse button.
So this means that it is your code that is causing that behaviour and as you haven't shown us the relevant section (or indeed any code), we cannot help you with this further. I suggest searching your application for PreviewMouseUp to see if this event is being manually raised anywhere.

Related

ReSize SizeChanged event not fired when clicking on an application running in the taskbar

I want to do something when the using clicks on an application running in the task bar. So I found out that I have to handle the ReSize and SizeChanged events.
I implemented event handlers for both and it sometimes works and sometimes doesn't.
By that I mean that sometimes when I click on the icon in the taskbar it would fire the event but sometimes it doesn't.
Has anyone experienced the same?
You can use the Form.Activated event to catch when the icon is clicked.

What is the difference between tap , mouse left button down and mouse pressed events?

Well, I am developing a windows phone app in c# and xaml.
I found these 3 events similar to each other.
the tap event, mouse left button down event and mouse pressed events.
Can anyone tell what exactly is the difference does these 3 events make when the phone is just a touch screen phone. What is unique difference between these 3 events ???..
Thanks..
If you down vote this question then tell atleast what is wrong in my question by comments..Sorry if this is too silly question.
This QuickStart Touch Input for Windows Phone page on MSDN, and this MouseLeftButtonUp Event page and this Mouse Position page explain the differences between the different events.
Basically, as per the links:
Tap
A finger touches the screen and releases.
MouseLeftButton
Is triggered in on finger release within the Tap event.
MousePressed
Mouse Pressed is the state of the tap while in Tap.
So the events are linked together of sorts. Someone with more experience with Windows Phone programming may be able to provide a better or more accurate explanation.
For all practical purposes, the Tap and Click events are equivalent for a Button.
The Click event was originally defined in Silverlight for desktop Windows and it is only defined for the Button control (and derivatives such as HyperlinkButton). You can think of the Click event as the "traditional" way to handle a Button press.
The Tap event was added to the framework in Windows Phone 7.1 (Mango). Tap is defined in the UIElement class, which is the parent of many types of controls. You can handle a Tap event in a TextBlock, Image, and many other controls. Button is subclassed from UIElement as well, and thus can also receive Tap events. It is redundant that a Button can receive both Tap and Click events.
reference
if u also read the second answer u can get some more info

C# Suppressing mouse click for multiple mice

I have written an application that currently handles clicks from multiple mouse devices.
I used this project and modified to handle mouse clicks as apposed to keyboards.
This is working fine, however now I need to know if there is a way to suppress a click event if it has been handled by my app. The app is a quiz game so the idea is that the quiz master will have (and still be able to use) 1 mouse, and the other contestants will have their own mouse (as buzzers). So when they buzz in, I don't want the mouse click events to fire in the operating system (or at least this application).
The concept is the familiar override of void WndProc(ref Message message), and so I have tried not calling base.WndProc(ref Message) when I don't want the click events to fire, but this has not worked.
Can anybody point me in the right direction here?
Should I be going down the windows hook route? I have looked at this, but I can't seem to work out how I could hook to each mouse device individually.
Any help would be greatly appreciated.
Edit:
This is a Windows Form UI project, and not WPF. So the MultiPoint SDK from Microsoft won't work.
The solution to this lies within not WndProc, but PreFilterMessage(). By intercepting messages before they even reach the form, you can remove them from the message pump causing them to never reach the control that was clicked. This also works for child controls within the form.
I answered this and posted the full source in the following question:
C# Get Mouse handle (GetRawInputDeviceInfo)

Run Action Upon Mouse Click and Mouse Release

I am working on a Windows Form C# project that requires running code when a user clicks down on a button, then waiting, and running a different set of code when the user then releases the mouse button. I have tried Button1.MouseDown and MouseUp as something that was suggested when I did a search for this information, but neither of these worked.
Does anyone know how to do this?
Thanks.
In visual studios, try clicking on the button and in properties, view the "Events" menu. You may have to scroll down and find Events "MouseDown" and Events "MouseUp".
Double click on each of this, which will load the class to work with.
Inside of those, you may add your code.
You can create a timer if you wish running at 100ms and if the user clicks the button and holds, then the timer goes and the moment he releases, inside that, you could have timer1.stop();

Can I use window hooks in C# to determine if a window gains or loses focus?

I've written a c# application which automates an instance of IE. I'd like to know when internet explorer gains focus and when it looses focus.
From the SHDocVw.InternetExplorer object I can get it's HWND. From there how can I create a message hook to receive WM_KILLFOCUS and WM_FOCUS events (assuming those are the correct events to be listening for :))?
Thanks everyone!!
UPDATE: I found a way I could use to accomplish the above goal without using hooks (which I haven't quite figured out how to do in c# yet), using the .NET framework in this question.
The problem with this code
AutomationFocusChangedEventHandler focusHandler
= new AutomationFocusChangedEventHandler(OnFocusChanged);
Automation.AddAutomationFocusChangedEventHandler(focusHandler);
is that it is easy for a window to be the foreground window and that event won't fire when that window is switched to because it's waiting for a specific UI Element to be in focus. (To test this you can use a function that uses that code and prints a message everytime a new window is in focus, such as the MSDN sample TrackFocus, and then click on a webbrowser. When most webpages or a blank page is being displayed in the browser the event wont fire until the address bar or some other element is selected.) It could probably work if there was a way to modify so that it could throw the event if either no UI Element is in focus or every time an element lost focus (instead being thrown when it gains focused). Anyone have any ideas on how I could fix the above code to solve my problem?
Update 2: I just came across this (article claims you can only hook to mouse and keyboard from c#) as well which may mean I can't use hooks at all for what I'd like to do.
Detailed instructions on setting up a hook from C# are here: http://support.microsoft.com/kb/318804/en-us?fr=1

Categories

Resources