Get cursor position with respect to the control - C#

前端 未结 11 2355
迷失自我
迷失自我 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:30

    private void lienzo_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
    {
        Point coordenadas = new Point();
        coordenadas = Mouse.GetPosition(lienzo);
    
        string msg = "Coordenadas mouse :" + coordenadas.X + "," + coordenadas.Y;
        MessageBoxResult resultado;
        string titulo = "Informacion";
        MessageBoxButton botones = MessageBoxButton.OK;
        MessageBoxImage icono = MessageBoxImage.Information;
    
        resultado = MessageBox.Show(msg, titulo, botones, icono);
    }
    

    Where "lienzo" is my canvas panel

提交回复
热议问题