0

我正在使用 .net Compact Framework 3.5 开发一个 Windows 移动应用程序框架,并且有一个包含基本自定义控件的 BaseControls 项目。这些控件之一是“TransparentLabel”。由于 .net CF 消除了很多设计时属性的功能,因此我必须使用 DesignTimeAttributes.xmta 文件来为我的控件属性指定默认值。

为我的控件设置默认大小时出现我的问题。以我的透明标签为例。我使用以下设置默认值:

<?xml version="1.0" encoding="utf-16"?>
<Classes xmlns="http://schemas.microsoft.com/VisualStudio/2004/03/SmartDevices/XMTA.xsd">
  <Class Name="BaseControls.TransparentLabel">
    <DesktopCompatible>true</DesktopCompatible>
    <ApplyDeviceDefaults>
      <PropertyName>Size</PropertyName>
      <ApplyDefaults>false</ApplyDefaults>
    </ApplyDeviceDefaults>
    <Property Name="Size">
      <DefaultValue>
        <Type>System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Type>
        <Value>110, 20</Value>
      </DefaultValue>
    </Property>
  </Class>
  <Class Name="BaseControls.TransparentControlBase">
    <DesktopCompatible>true</DesktopCompatible>
  </Class>
</Classes>

但是,当我将TransparentLabel 实例拖放到表单上时,大小会加倍(即220x40)。我认为这与我正在为分辨率是 QVGA 设备两倍的 VGA 设备开发框架有关,但我不知道如何阻止这种情况。我尝试将目标表单上的 AutoScaleMode 属性设置为 Dpi 和 None,但没有效果。现在我意识到我可以将默认值设置为我实际想要的一半,并将其缩放到所需的大小,但我想了解是什么导致了这种情况以及如何停止它。

非常感谢提前!

编辑 下面的代码显示了将透明标签从工具箱拖到窗体上时窗体的设计器文件中生成的代码。如您所见,大小是我在设计时属性文件中指定的两倍。

        // 
        // transparentLabel1
        // 
        this.transparentLabel1.Location = new System.Drawing.Point(100, 178);
        this.transparentLabel1.Name = "transparentLabel1";
        this.transparentLabel1.Size = new System.Drawing.Size(220, 40);
        this.transparentLabel1.TabIndex = 17;
        this.transparentLabel1.Text = "transparentLabel1";
        this.transparentLabel1.TextAlign = System.Drawing.ContentAlignment.TopLeft;
4

0 回答 0