2016-06-28 64 views
0

如何將文本框居中在我的Windows 10應用程序頁面中?我測試了 button1.Left = (width - button1.width)/2但它沒有工作。中心文本框

回答

0

你已經嘗試使用Client1.Lidth爲你的button1.Location屬性?

button1.Location = New Point((ClientSize.Width - button1.Width)/2, _ 
          (ClientSize.Height - button1.Height) /2) 

該代碼應該居中控制button1在頁面的中心使用寬度和高度,但Point類也只接受一個參數。

+1

我會嘗試這個感謝 –

0

你應該利用框架的力量而不是自己做計算。有2個選項來做到這一點使用HorizontalAlignment屬性:

在XAML:

<Button x:Name="Button1" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Button 1" /> 

在代碼:

Button1.HorizontalAlignment = HorizontalAlignment.Center