窗体上放一个大的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
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
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的不同。好像是各弱智的问题。研究下。
再次表示感谢。
this.ClientRectangle !=this.Size
flowlayoutpanel和tablelayoutpanl啊和web中的table,div差不多,都是用来定位的
1:重写窗体的OnSizeChanged方法,并处理大小位置,或在SizeChanged事件里处理也是一样的。不能只在初始的时候设置。
2:设置窗体的Padding 属性全部为6,或使用代码:this.Padding = new Padding(6, 6, 6, 6);并把Panel的Dock设置为Fill。
试试
就是单独建立一个测试项目可以的。但把修改应用的正真的项目里就不行了。---------------------------
winform布局使用专用的布局控件啊
flowlayoutpanel和tablelayoutpanl啊 谢谢
--------------------
设置窗体的Padding 属性全部为6,或使用代码:this.Padding = new Padding(6, 6, 6, 6);并把Panel的Dock设置为Fill。可以考虑
谢谢
---谢谢各位的回答