[英]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=">>lbl_multi_component_brine_.Name" xml:space="preserve">
<value>lbl_multi_component_brine_</value>
</data>
<data name=">>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=">>lbl_multi_component_brine_.Parent" xml:space="preserve">
<value>panel_mc_brine_</value>
</data>
<data name=">>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.