How do I convert a WPF size to physical pixels?

前端 未结 4 1433
灰色年华
灰色年华 2020-11-28 21:21

What\'s the best way to convert a WPF (resolution-independent) width and height to physical screen pixels?

I\'m showing WPF content in a WinForms Form (via ElementHo

4条回答
  •  自闭症患者
    2020-11-28 22:26

    Just did a quick lookup in the ObjectBrowser and found something quite interesting, you might want to check it out.

    System.Windows.Form.AutoScaleMode, it has a property called DPI. Here's the docs, it might be what you are looking for :

    public const System.Windows.Forms.AutoScaleMode Dpi = 2 Member of System.Windows.Forms.AutoScaleMode

    Summary: Controls scale relative to the display resolution. Common resolutions are 96 and 120 DPI.

    Apply that to your form, it should do the trick.

    {enjoy}

提交回复
热议问题