2011-09-27 12 views
0

我的.net winforms程序中有一些自定義用戶控件,當用戶選擇了較大的文本大小時無法正確顯示。此設置: enter image description here在Windows 7中的控制縮放問題

我控制這個樣子,

enter image description here

,而不是像這樣,

enter image description here

該法案面積和船區均有自定義控件。我不知道這是造成這個問題的,但我有在每個代碼,以幫助縮放電話/傳真方面很好地伸展,就像從法案以控制該代碼,

Private Sub panFaxPhone_Resize(sender As Object, e As System.EventArgs) Handles panFaxPhone.Resize 
      panFax.Width = (panFaxPhone.Width/2) - 1 
      panPhone.Width = (panFaxPhone.Width/2) - 1 
      panFax.Left = panFaxPhone.Width - panFax.Width 
    End Sub 

我怎麼能讓我的控件尺寸正確,同時還要尊重用戶對較大文本的選擇(我不想只將AutoScaleMode設置爲None)?

更新: 長時間玩這個遊戲後,它似乎是一個與兒童控制中的錨問題。看到下面的圖像,內部的黑色框是邊框打開的控件,文本框(如名稱)左側和右側錨定,並應伸展以填充控件,但不要。

enter image description here

回答

1

這只是普通的好像默認的控制比例只是不與錨的工作。我不知道爲什麼,也無法解釋它。但我找到了解決辦法。請參閱下面我添加到控件中的代碼。如果你能提供解釋,我將不勝感激。

Private ChildControlScale As Double = 0 
    Public Sub New() 

     ' This call is required by the designer. 
     InitializeComponent() 

     ' Add any initialization after the InitializeComponent() call. 
     ChildControlScale = txtAddress.Width/Me.Width 

    End Sub 

    Protected Overrides Sub ScaleControl(factor As System.Drawing.SizeF, specified As System.Windows.Forms.BoundsSpecified) 
     MyBase.ScaleControl(factor, specified) 
     If ChildControlScale <> 0 Then 
      For Each ctrl As Control In Me.Controls 
       ctrl.Width = Me.Width * ChildControlScale 
      Next 
     End If 
    End Sub