本文介绍了为什么设置分离器的位置如此困难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
下面给出的代码内容;需要3个面板和2个分离器。但是,第二个分离器(绿色)必须位于灰色和棕色面板之间。但不是在正确的地方。有什么建议吗?谢谢。
Hi everyone,
The content of the codes given below; 3 panels and 2 Splitter are required. However, the 2nd splitter (Green) must be located between the gray and brown panel. But not in the right place. Are there any suggestions? Thanks.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Show()
Dim tmpSplitter As Splitter
Dim tmpPanel As Panel
Dim MainPanel As Panel
' This is main panel
'
MainPanel = New Panel
With MainPanel
.Name = "MainPanel"
.Dock = DockStyle.Fill
.BackColor = Color.LightGray
.BorderStyle = BorderStyle.Fixed3D
.Visible = True
End With
Me.Controls.Add(MainPanel)
' 1: First Top Panel and Splitter
'
tmpPanel = New Panel
With tmpPanel
.Name = "Panel1"
.Dock = DockStyle.Top
.BackColor = Color.Red
.Visible = True
End With
tmpSplitter = New Splitter
With tmpSplitter
.Name = "Split1"
.Dock = DockStyle.Top
.BackColor = Color.Blue
.Cursor = Cursors.HSplit
End With
Me.Controls.Add(tmpSplitter)
Me.Controls.Add(tmpPanel)
' 2: Second Panel added to the left side of the main panel
'
MainPanel.Dock = DockStyle.Right
MainPanel.Size = New Size(MainPanel.Width * 0.5, MainPanel.Height)
Dim btn As New Button
btn.Size = New Size(10, 50)
btn.Location = New Point(MainPanel.Location.X - btn.Width, MainPanel.Location.Y)
Me.Controls.Add(btn)
tmpPanel = New Panel
With tmpPanel
.Size = New Size(10, MainPanel.Height)
.Location = New Point(MainPanel.Location.X - .Width - 5, MainPanel.Location.Y)
.Name = "Panel2"
.Dock = DockStyle.Fill
.BackColor = Color.Brown
End With
' THIS SPLITTER IS NOT IN THE RIGHT PLACE. Must be between brown and gray panel
'
tmpSplitter = New Splitter
With tmpSplitter
.Size = New Size(5, MainPanel.Height)
.Location = New Point(MainPanel.Location.X - .Width, MainPanel.Location.Y)
.Name = "Split2"
.Dock = DockStyle.Right
.BackColor = Color.Green
.Cursor = Cursors.VSplit
End With
Me.Controls.Add(tmpSplitter)
Me.Controls.Add(tmpPanel)
End Sub
End Class
我尝试过:
我改变了Splitter的位置,但这并非毫无意义。它可以在设计阶段手动完成,但在运行时无法使用代码完成。
What I have tried:
I changed the location of Splitter, but it wasn't meaningless. It can be done manually during the design phase, but it cannot be done with code at run time.
推荐答案
Me.Controls.SetChildIndex (tmpSplitter, 0)
足以在最后一行写入。感谢您的贡献
is enough to write on the last line. Thank you for your contributions
这篇关于为什么设置分离器的位置如此困难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!