简体   繁体   English

Windows Forms 动态更改位置时,应用程序 DPI 支持不起作用

[英]Windows Forms application DPI support does not work when location is changed dynamically

There is a Windows Forms application with DPI support enabled.有一个启用了 DPI 支持的 Windows Forms 应用程序。 Following label is properly aligned when I change display scaling and run the app again.当我更改显示比例并再次运行应用程序时,以下 label 正确对齐。 I need to change its location depending to some condition, so I did it in C++ by setting Location property of lbl_multi_component_brine_.我需要根据某些情况更改其位置,因此我在 C++ 中通过设置 lbl_multi_component_brine_ 的 Location 属性来完成。 In that case DPI support doesn't work for some reason.在那种情况下,DPI 支持由于某种原因不起作用。 The label is always shown on that location no matter display scaling.无论显示缩放比例如何,label 始终显示在该位置。 Does it mean that DPI support only works when location is specified in Resource file?这是否意味着 DPI 支持仅在资源文件中指定位置时才有效? Does it mean that I should calculate coordinates taking into account the DPI and set in C++ or there is some solution that will skip that calculations.这是否意味着我应该在考虑 DPI 的情况下计算坐标并在 C++ 中设置,或者有一些解决方案会跳过该计算。

  <data name="lbl_multi_component_brine_.AutoSize" type="System.Boolean, mscorlib">
    <value>True</value>
  </data>
  <data name="lbl_multi_component_brine_.Location" type="System.Drawing.Point, System.Drawing">
    <value>19, 10</value>
  </data>
  <data name="lbl_multi_component_brine_.Size" type="System.Drawing.Size, System.Drawing">
    <value>92, 13</value>
  </data>
  <data name="lbl_multi_component_brine_.TabIndex" type="System.Int32, mscorlib">
    <value>148</value>
  </data>
  <data name="lbl_multi_component_brine_.Text" xml:space="preserve">
    <value>Brine</value>
  </data>
  <data name="&gt;&gt;lbl_multi_component_brine_.Name" xml:space="preserve">
    <value>lbl_multi_component_brine_</value>
  </data>
  <data name="&gt;&gt;lbl_multi_component_brine_.Type" xml:space="preserve">
    <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </data>
  <data name="&gt;&gt;lbl_multi_component_brine_.Parent" xml:space="preserve">
    <value>panel_mc_brine_</value>
  </data>
  <data name="&gt;&gt;lbl_multi_component_brine_.ZOrder" xml:space="preserve">
    <value>0</value>
  </data>

I fixed that by considering DPI every time I set coordinate in C++ using this function to transform it:我通过每次在 C++ 中设置坐标时考虑 DPI 使用此 function 对其进行转换来解决此问题:

static int DPI_POS(int pos, System::Windows::Forms::Control^ control) 
{
  System::Drawing::Graphics^ g = control->CreateGraphics();
  return int(pos * g->DpiX / 96);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 Makefile 中更改源位置时无法构建代码? - Why does code can not be build when source location is changed in Makefile? 在win32应用程序中动态设置DPI感知级别 - Setting DPI awareness level dynamically in win32 Application Windows窗体应用程序错误 - Windows Forms Application error 使用 Windows API 调整屏幕大小时,DPI 感知会扭曲文本 - DPI aware distorts text when screen resized with Windows API Windows Forms应用程序中的链接器错误 - Linker errors in a Windows Forms Application MS窗口中的应用程序路径位置 - Application path location in MS windows Windows错误报告何时创建转储文件? 它是可配置的吗? 这在Windows 7中有变化吗? - When does Windows Error Reporting create a dump file? Is it configurable? Has this changed in Windows 7? C ++中Windows窗体应用程序中的OpenFileDialog-&gt; Filter不起作用 - OpenFileDialog->Filter in windows form application in C++ does not work 如何创建与Windows 7向后兼容的缩放和大小更改Per-Monitor DPI感知应用程序? - How to create a scaling and size-changing Per-Monitor DPI-aware application that is backwards compatible with Windows 7? 使用VC ++ 2008编译Windows窗体应用程序时出现LNK2001错误 - LNK2001 error when compiling windows forms application with VC++ 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM