Get cursor position with respect to the control - C#

前端 未结 11 2356
迷失自我
迷失自我 2020-12-05 23:23

I want to get the mouse position with respect to the control in which mouse pointer is present. That means when I place the cursor to the starting point (Top-Left corner) of

11条回答
  •  悲哀的现实
    2020-12-05 23:51

    Simply subtract from the cursor position the Left and Top coordinates of the control:

    this.Text = Convert.ToString(
        Cursor.Position.X - this.Left + ":" +
        Cursor.Position.Y - this.Top);
    

提交回复
热议问题