次の方法で共有


Getting system DPI in WPF app..

it only took less than an hour for some one to ask why my last post has this code:

Matrix m =
PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
double dx = m.M11;
double dy = m.M22;

The multiple choice answer is:
a) habit, not paying attention
b) filling space, not paying attention
c) not paying attention

The  code gets the horizontal (M11), vertical (M22) DPI on my system..   The actual value are divided by 96 ...  [going back to WPF's device independent logical units in wpf being 1/96 of an inch]... so for example, my system at 144 DPI so I get 1.5  ... 

Technically, WindowsFormsHost does NOT need that code; it is supposed to do that translation for you, if you give it a windows forms control that is not sized.

Sorry ..