窗体上放一个大的panel(pnlGlobal),pnlGlobal里上下各一个panel(pnlcaption,pnlContent)。
pnlGlobal的宽度和高度比当前窗体各小6
Me.pnlGlobal.Location = New Point(3, 3)
这样以来,pnlGlobal在窗体里面,它距离窗体的上下左右距离都是3,这样就能造出边框来了。但是为什么pnlGlobal右边和下边离窗体的距离居然小于3,导致右边和下边没有边框了。为什么呢????
Public Class WindowDockParent  Public Shared BorderColor As System.Drawing.Color  Private Sub WindowDockParent_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    BorderColor = Color.Blue
    'Me.pnlGlobal.Size = New Size(Me.Size.Width - 6 - 8, Me.Size.Height - 6 - 28)
    Me.pnlGlobal.Size = New Size(Me.Size.Width - 6, Me.Size.Height - 6)
    Me.pnlCaption.Size = New Size(pnlGlobal.Size.Width, 22)
    Me.pnlContent.Size = New Size(pnlGlobal.Size.Width, Me.pnlGlobal.Size.Height - 22)
    Me.pnlCaption.BackColor = Color.Black
    Me.pnlContent.BackColor = Color.Red
    Me.pnlGlobal.BackColor = Color.Yellow    Me.pnlGlobal.Location = New Point(3, 3)
    Me.pnlCaption.Location = New Point(0, 0)
    Me.pnlContent.Location = New Point(0, 22)
    Me.MinimumSize = New Size(150, 22)
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
     End Sub
  Private Sub mPrDrawBorder(ByVal g As Graphics)
    ControlPaint.DrawBorder(g, Me.ClientRectangle, _
            BorderColor, 3, ButtonBorderStyle.Solid, _
            BorderColor, 3, ButtonBorderStyle.Solid, _
            BorderColor, 3, ButtonBorderStyle.Solid, _
            BorderColor, 3, ButtonBorderStyle.Solid)
  End Sub
  Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
    MyBase.OnPaintBackground(e)
    mPrDrawBorder(e.Graphics)
  End SubEnd Class<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class WindowDockParent
    Inherits System.Windows.Forms.Form    'Form 重写 Dispose,以清理组件列表。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改它。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
    Me.pnlCaption = New System.Windows.Forms.Panel
    Me.pnlGlobal = New System.Windows.Forms.Panel
    Me.pnlContent = New System.Windows.Forms.Panel
    Me.pnlGlobal.SuspendLayout()
    Me.SuspendLayout()
    '
    'pnlCaption
    '
    Me.pnlCaption.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.pnlCaption.Location = New System.Drawing.Point(-5, -5)
    Me.pnlCaption.Margin = New System.Windows.Forms.Padding(0)
    Me.pnlCaption.Name = "pnlCaption"
    Me.pnlCaption.Size = New System.Drawing.Size(20, 0)
    Me.pnlCaption.TabIndex = 0
    '
    'pnlGlobal
    '
    Me.pnlGlobal.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.pnlGlobal.Controls.Add(Me.pnlCaption)
    Me.pnlGlobal.Controls.Add(Me.pnlContent)
    Me.pnlGlobal.Location = New System.Drawing.Point(-5, -5)
    Me.pnlGlobal.Margin = New System.Windows.Forms.Padding(0)
    Me.pnlGlobal.Name = "pnlGlobal"
    Me.pnlGlobal.Size = New System.Drawing.Size(10, 10)
    Me.pnlGlobal.TabIndex = 1
    '
    'pnlContent
    '
    Me.pnlContent.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                Or System.Windows.Forms.AnchorStyles.Left) _
                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.pnlContent.Location = New System.Drawing.Point(-5, -5)
    Me.pnlContent.Margin = New System.Windows.Forms.Padding(0)
    Me.pnlContent.Name = "pnlContent"
    Me.pnlContent.Size = New System.Drawing.Size(20, 20)
    Me.pnlContent.TabIndex = 1
    '
    'WindowDockParent
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.BackColor = System.Drawing.Color.Thistle
    Me.ClientSize = New System.Drawing.Size(559, 499)
    Me.Controls.Add(Me.pnlGlobal)
    Me.Name = "WindowDockParent"
    Me.Text = "WindowDockParent"
    Me.pnlGlobal.ResumeLayout(False)
    Me.ResumeLayout(False)  End Sub
  Friend WithEvents pnlCaption As System.Windows.Forms.Panel
  Friend WithEvents pnlGlobal As System.Windows.Forms.Panel
  Friend WithEvents pnlContent As System.Windows.Forms.Panel
End Class

解决方案 »

  1.   

    用splitContainer如果用panel的话,参考form或者panel的ClientSize而不是Size
      

  2.   

    星级人物的对话,能看到不容易,特来捧场.至于LZ的问题,也许应该把panel的anchor属性设置为left,top,right,bottom,即上下左右都通通锚定.
      

  3.   

    主要是对话框边框的原因,你把FormBorderStyle改为None效果就出来了
      

  4.   

    谢谢各位,这个例子里是由于
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None的顺序问题造成的,
      Private Sub WindowDockParent_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        BorderColor = Color.Blue
        'Me.pnlGlobal.Size = New Size(Me.Size.Width - 6 - 8, Me.Size.Height - 6 - 28)
        Me.pnlGlobal.Size = New Size(Me.Size.Width - 6, Me.Size.Height - 6)
        Me.pnlCaption.Size = New Size(pnlGlobal.Size.Width, 22)
        Me.pnlContent.Size = New Size(pnlGlobal.Size.Width, Me.pnlGlobal.Size.Height - 22)
        Me.pnlCaption.BackColor = Color.Black
        Me.pnlContent.BackColor = Color.Red
        Me.pnlGlobal.BackColor = Color.Yellow    Me.pnlGlobal.Location = New Point(3, 3)
        Me.pnlCaption.Location = New Point(0, 0)
        Me.pnlContent.Location = New Point(0, 22)
        Me.MinimumSize = New Size(150, 22)     End Sub
    是可以的。是size、clientSize的不同。好像是各弱智的问题。研究下。
    再次表示感谢。
      

  5.   

    这个是因为窗体本身的边框的宽度就应该不止3。所以导致这样的,要让pnlGlobal右边也有边框的话,估计宽度还要小很多
      

  6.   

    Me.pnlGlobal.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top;//Anchor 属性 这是C# 里的 不知道VB有没得
      

  7.   

    当 Windows.Forms.FormBorderStyle.None 的时候 size和clientsize是一样的。简单项目可以,为什么在开发项目里就不行呢?郁闷。
      

  8.   

    边框线有多宽你知道不?要减去这个
    this.ClientRectangle !=this.Size 
      

  9.   

    winform布局使用专用的布局控件啊
    flowlayoutpanel和tablelayoutpanl啊和web中的table,div差不多,都是用来定位的
      

  10.   

    结合控件的dock和anchor两个属性,可以做的很好
      

  11.   

    有两个方式楼主可以试一下:
    1:重写窗体的OnSizeChanged方法,并处理大小位置,或在SizeChanged事件里处理也是一样的。不能只在初始的时候设置。
    2:设置窗体的Padding 属性全部为6,或使用代码:this.Padding = new Padding(6, 6, 6, 6);并把Panel的Dock设置为Fill。
      

  12.   

    Me.ClientRectangle 改 new Rectangle(0, 0, Me.Width, Me.Height) 
    试试 
      

  13.   


    就是单独建立一个测试项目可以的。但把修改应用的正真的项目里就不行了。---------------------------
    winform布局使用专用的布局控件啊 
    flowlayoutpanel和tablelayoutpanl啊 谢谢
    --------------------
    设置窗体的Padding 属性全部为6,或使用代码:this.Padding = new Padding(6, 6, 6, 6);并把Panel的Dock设置为Fill。可以考虑
    谢谢
    ---谢谢各位的回答