D
D
Denis2021-03-02 16:57:43
C++ / C#
Denis, 2021-03-02 16:57:43

How to find out the location of the cursor?

How do I get the coordinates of the mouse relative to panel ( panel is a component in winforms, I think everyone knows), when reading the KeyEventArgs event . I'll give you an example.

private void button_KeyDown(object sender, KeyEventArgs e)
{
    // Тут надо роспознать кординати миши относительно Panel
}


Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2021-03-02
Folyush @AAGR

Long story short, I found a workaround.

int CursorToFormX = this.PointToClient(Cursor.Position).X;
int CursorToFormY = this.PointToClient(Cursor.Position).Y;

int SizeTreeView = treeView1.Size.Width + 18;
int PositionPasteX = (SizeTreeView - CursorToFormX) - (SizeTreeView - CursorToFormX) - (SizeTreeView - CursorToFormX);

int SizeCaptionAndMenuStrip = int.Parse(SystemInformation.CaptionHeight.ToString()) + 6;
int PositionPasteY = (SizeCaptionAndMenuStrip - CursorToFormY) - (SizeCaptionAndMenuStrip - CursorToFormY) - (SizeCaptionAndMenuStrip - CursorToFormY);

V
Vladimir Yurchenkov, 2021-03-02
@EPIDEMIASH

/Получаем координаты курсора
int CX = Cursor.Position.X;
int CY = Cursor.Position.Y;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question