有一个WPF的程序,上面有一个自定义的cursor,希望在DPI变化时,那个cursor跟着变大或变小。有什么好办法吗?
谢谢。能想到的办法是做三个不同大小的cursor,然后,在不同dpi下,用不定cursor.

解决方案 »

  1.   

    从别处找了一段得dpi的。WPF有自带的能解决问题的方法吗?
            private const int HORZRES = 8;
            private const int VERTRES = 10;
            private const int LOGPIXELSX = 88;
            private const int LOGPIXELSY = 90;        [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
            private static extern IntPtr GetDC(IntPtr hWnd);        [DllImport("Gdi32.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
            private static extern int GetDeviceCaps(IntPtr hdc, int nIndex);        private const int kBaseDpi = 96;
            private const int kLargeDpi = 144;
            private const int kLargest = 192;        static int getDpi()
            {
                IntPtr dc = GetDC(IntPtr.Zero);
                return GetDeviceCaps(dc, LOGPIXELSX);
            }
      

  2.   


    Matrix m =
    PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
    double dx = m.M11;
    double dy = m.M22; From: 
    http://blogs.msdn.com/b/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx