首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么设置Splitter的位置会如此困难?

为什么设置Splitter的位置会如此困难?
EN

Stack Overflow用户
提问于 2019-02-18 16:24:13
回答 1查看 41关注 0票数 0

下面给出的代码内容;需要3个面板和2个拆分器。但是,第二个拆分器(绿色)必须位于灰色和棕色面板之间。但不是在正确的地方。有什么建议吗?谢谢。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-02-19 22:39:08

多做一点研究,试着解决这个问题

代码语言:javascript
复制
Me.Controls.SetChildIndex (tmpSplitter, 0)

足够写在最后一行了。感谢您的贡献。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54743051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档