【问题标题】:Rotate Grid around cursor position?围绕光标位置旋转网格?
【发布时间】:2013-10-11 10:29:00
【问题描述】:

我有这个功能:

private void RightTap_Rotate(object sender, RightTappedRoutedEventArgs e)
    {
        var obj = (CompositeTransform)N.RenderTransform;
        obj.Rotation += 90;

    }

因此,右键单击网格 (N) 后,它会旋转到 90,但不是围绕光标位置(是的,在左角附近)。

我需要用什么来围绕光标旋转它?

【问题讨论】:

    标签: c# wpf xaml windows-8


    【解决方案1】:

    设置变换的中心点:

    private void RightTap_Rotate(object sender, RightTappedRoutedEventArgs e)
    {
        var obj = (CompositeTransform)N.RenderTransform;
        Point cursorPos = Mouse.GetPosition(yourControl);
        obj.CenterX = cursorPos.X;
        obj.CenterY = cursorPos.Y;
        obj.Rotation += 90;
    }
    

    【讨论】:

    • 谢谢,但是我应该为«鼠标»使用什么?我尝试了«Control.Mouse»和«System.Windows.Inout»但什么也没发生。 VS 2013,Windows 8.1
    • 使用e.GetPosition获取位置。
    猜你喜欢
    • 2014-12-27
    • 2017-08-10
    • 2022-11-23
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2015-05-14
    相关资源
    最近更新 更多