Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The solution to this problem is simple. All what you need is a System.Windows.Forms.Timer, and use DllImport from System.Runtime.InteropService to extern the method GetKeyState from user32.dll. This function has one parameter of any type of integer, and it returns short (Int16). This function can tell you if some keys were pressed or not at every moment and everywhere, not depending on the form. While the Timer is Enabled, you can check if the mouse position is out of the form bounds. There are many ways to get the mouse position. One way is Cursor.Position, or Control.MousePosition, or you can use the bool GetCursorPos(ref Point lpPoint), an extern method, that you can DllImport it from "user32.dll". form.Bounds or form.ClientRectangle, or form.Location and form.Size or form.Left and form.Top and form.Width and form.Height, all these bring you the form bounds. In the timer_Tick function event, you write the following code for example: {</p> <pre><code> Point mp = Cursor.Position; Rectangle fb = form.ClientRectangle; //or form.Bounds if (mp.X &lt; fb.X || mp.Y &lt; fb.Y || mp.X &gt; fb.X + fb.Width || mp.Y &gt; fb.Y + fb.Height) { //use GetKeyState from user32.dll to detect if at least 1 key is pressed //(look at internet how to do it exactly) //if yes MessageBox.Show("Clicked outside"); } </code></pre> <p>} If at least 1 key was pressed, and then Show your message with the MessageBox. You can read on the Internet how to do all these stuff I was talking about before, and if you suceed, it will work!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload