2013-12-18 28 views
0

我幾乎花了2個小時對這些控件進行試驗和錯誤。我需要一些幫助。 enter image description here
是我目標 ..能夠三人都停靠在右邊,XY是進度..和下X Y的跟蹤條。(下我最大化我的形式,所以我需要對接它),除非你有一些很酷的技巧,可以自動適應..如何安排在碼頭模式下的控制

X和Y是標籤..我顯示我的地圖座標。
然後在它們下面是一個PanelTrackBar ..

解決方案嘗試 - 結果:

  • 停靠他們沒事 - X面板Y/XY面板
  • 把三板和碼頭右側 - XY軌跡其中消耗的寬度太大
  • 無面板,停靠三個右側 - 軌跡XY
  • dock X Y top - 出現在左上方,X以下Y

我沒有達到我想要的..任何想法?

+0

您可以嘗試將所有控件添加到FlowLayoutPanel。 –

回答

2

將所有控件添加到FlowLayoutPanel

將面板的流動方向設置爲「RightToLeft」。

Me.FlowLayoutPanel1.FlowDirection = FlowDirection.RightToLeft 

在設計器中,選擇面板中包含的所有控件,並將屬性「FlowBreak」設置爲「True」。

替代

您也可以創建自己的流面板。

Public Class MyFlowPanel 
    Inherits Panel 

    Protected Overrides Function CreateControlsInstance() As System.Windows.Forms.Control.ControlCollection 
     Return New ControlCollection(Me) 
    End Function 

    Private Sub EnsureLayout(sender As Object, e As EventArgs) 
     If (Not Me.isUpdatingLayout) Then 
      Me.UpdateLayout() 
     End If 
    End Sub 

    Private Sub NotifyControlIndexChanged(child As Control) 
     'This will cause some selection issues in designer. 
     'Implement a custom designer to fix this. 
     Me.UpdateLayout() 
    End Sub 

    Protected Overrides Sub OnControlAdded(e As System.Windows.Forms.ControlEventArgs) 
     AddHandler e.Control.SizeChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     AddHandler e.Control.LocationChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     AddHandler e.Control.Resize, New EventHandler(AddressOf Me.EnsureLayout) 
     AddHandler e.Control.MarginChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     MyBase.OnControlAdded(e) 
     Me.UpdateLayout() 
    End Sub 

    Protected Overrides Sub OnControlRemoved(e As System.Windows.Forms.ControlEventArgs) 
     RemoveHandler e.Control.SizeChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     RemoveHandler e.Control.LocationChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     RemoveHandler e.Control.Resize, New EventHandler(AddressOf Me.EnsureLayout) 
     RemoveHandler e.Control.MarginChanged, New EventHandler(AddressOf Me.EnsureLayout) 
     MyBase.OnControlRemoved(e) 
     Me.UpdateLayout() 
    End Sub 

    Protected Overrides Sub SetBoundsCore(x As Integer, y As Integer, width As Integer, height As Integer, specified As System.Windows.Forms.BoundsSpecified) 
     MyBase.SetBoundsCore(x, y, width, height, specified) 
     Me.UpdateLayout() 
    End Sub 

    Private Sub UpdateLayout() 
     Me.isUpdatingLayout = True 
     Dim top As Integer = Me.ClientRectangle.Top 
     Dim right As Integer = Me.ClientRectangle.Right 
     Dim c As Control 
     For index = 0 To (Me.Controls.Count - 1) 
      c = Me.Controls.Item(index) 
      top += c.Margin.Top 
      c.Location = New Point((right - (c.Width + c.Margin.Right)), top) 
      top += (c.Height + c.Margin.Bottom) 
     Next 
     Me.isUpdatingLayout = False 
    End Sub 

    Private isUpdatingLayout As Boolean 

    Public Shadows Class ControlCollection 
     Inherits Panel.ControlCollection 
     Public Sub New(owner As MyFlowPanel) 
      MyBase.New(owner) 
      Me.owner2 = owner 
     End Sub 
     Public Overrides Sub SetChildIndex(child As System.Windows.Forms.Control, newIndex As Integer) 
      MyBase.SetChildIndex(child, newIndex) 
      Me.owner2.NotifyControlIndexChanged(child) 
     End Sub 
     Private owner2 As MyFlowPanel 
    End Class 

End Class 
+0

沒有完全解決它。 trackbar不希望'flowlayoutpanel'哈哈無論如何,謝謝你的信息。 – AdorableVB

相關問題