C# 设计时属性文件:默认控件大小加倍

C# 设计时属性文件:默认控件大小加倍,c#,.net,windows-mobile,C#,.net,Windows Mobile,我正在使用.net Compact framework 3.5开发一个windows mobile应用程序框架,并且有一个包含基本自定义控件的BaseControls项目。其中一个控件是“TransparentLabel”。由于.net CF消除了设计时属性的许多功能,因此我必须使用DesignTimeAttributes.xmta文件来指定控件属性的默认值 设置控件的默认大小时出现问题。以我的透明标签为例。我使用以下方法设置默认值: <?xml version="1.0" encodin

我正在使用.net Compact framework 3.5开发一个windows mobile应用程序框架,并且有一个包含基本自定义控件的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>

我不确定这是否有帮助,但是.NET控件有一个自动调整大小属性,该属性必须设置为DPI,以便控件在VGA和QVGA之间自动调整大小。如果您正在绘制自定义控件,则可能必须使用环境的DPI来重新缩放控件。@Josef您是指窗体的AutoScaleMode属性吗?我在控件或UserControls上都没有看到AutoResize属性,我尝试了表单属性AutoScaleMode(DPI、Inherit、None)的所有可能值,但没有效果。我不需要我的控件在VGA和QVGA之间自动缩放,因为我们只是标记VGA设备,但这似乎是一个逻辑位置,可以开始了解我所有控件的缩放方式。抱歉,AutoScaleMode仅适用于窗体。因此,请检查表格销售模式。我假设放置在表单中的控件将继承该设置。AutoScaleMode的联机帮助说它是ContainerControl的一个属性。@Josef您的建议很有意义,实际上正是我所想的。奇怪的是,我在编译我的项目时,Forms AutoScaleMode设置为DPI和None,在这两种情况下,当我将自定义控件放到窗体上时,其大小是我在设计时属性文件中指定的大小的两倍。我不确定如何设计控件。我只知道如何在VS中添加自定义控件,然后在VS中以可视模式进行设计。让我紧张的是您的桌面兼容设置。我记得自定义控件在桌面设计模式下的行为可能会很奇怪。
        // 
        // 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;