2012-08-23 11 views
1

嗨,我已经开发了一个Windows窗体应用程序,我部署它,我将它安装在另一个系统上,使用不同的屏幕去除方式,我的一些控件看起来并不像他们在我自己的系统上做的那样,例如我有一个groupbox中的lables在目标机器中,他们已经超过了组合盒的机芯!我想知道我应该如何正确设置不同控件的不同大小属性,以便在不同的系统上以不同的屏幕尺寸显示不同的屏幕?如何设置.NET赢得应用程序控制大小属性在不同的系统上具有相同的外观?

在此先感谢您的回复

+1

你说的是DPI,而不是分辨率。 – SLaks

+0

@SLaks ok,thx,我该怎么办? – Karamafrooz

+1

我假设你使用WinForms? – SLaks

回答

1

我会假设你正在使用的Windows Presentation Foundation(WPF);如果是这样,您需要在GroupBox控件中设置一个Grid。如果你习惯于HTML,你可以将Grid看作是一个表格。然后将您的标签或其他控件放在网格中。下面是一个例子,一定要注意保证金标签。他们是网格中控制的位置。

<GroupBox Header="groupBox1" Height="135" HorizontalAlignment="Left" Margin="12,78,0,0" Name="groupBox1" VerticalAlignment="Top" Width="287"> 
    <Grid> 
     <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="45,28,0,0" Name="label1" VerticalAlignment="Top" /> 
    </Grid> 
</GroupBox> 

要在Windows窗体中执行相同操作,您需要手动将控件添加到GroupBox。

gbCtrl = new GroupBox(); 
gbCtrl.Left = 20; // <- These are relative to the main form. 
gbCtrl.Top = 20; 
gbCtrl.Width = 120; 
gbCtrl.Height = 60; 
gbCtrl.Text = "Sample GroupBox"; 

Button btnSample = new Button(); 
btnSample .Left = 22; // <- These are relative to the groupbox 
btnSample .Top = 24; // 
gbCtrl.Controls.Add(btnSample); // <- Add the button to the groupbox 

Controls.Add(gbCtrl); // <- Add the groupbox to the main form. 
+0

thx为yoyr回复,但我没有使用WPF,我正在使用windows窗体apllication – Karamafrooz

+0

@Karamafrooz我的猜测是你没有添加你的标签控件属于主窗体,而不是groupbox控件。看到我上面编辑的帖子。 – Menefee

相关问题