I found a video and a source code on which I am working; to get the coordinates by clicking outside the form. I have tried to tie it to events: By clicking (right / left) or pressing the "F11" key; But it doesn't work properly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace iMouse
{
public partial class Events : Form
{
public bool TrackerSt;
public FormMouseCR()
{
InitializeComponent();
}
public void ButtonGetCoord_Click(object sender, EventArgs e)
{
Visible = false;
TrackerSt = true;
int x = Cursor.Position.X;
int y = Cursor.Position.Y;
int size = 10; // Arbitrary size
System.Drawing.Graphics graphics = CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(x - (size / 2), y - (size / 2), size, size);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);
}
private void FormMouseCR_MouseClick(object sender, MouseEventArgs e)
{
if(TrackerSt){
label1.Text = "X = " + e.X + " ; Y = " + e.Y;
TrackerSt = false;
}
}
private void FormMouseCR_MouseMove(object sender, MouseEventArgs e)
{
if(TrackerSt){
label1.Text = "X = " + e.X + " ; Y = " + e.Y;
}
}
}
}
I also think about changing the default cursor icon with that of a target and that it is centered, similar to a straight shooter sight, but I haven't found anything similar, only that i have in my code.
but this not work properly. iam dont know that i am missing?