vb.net - WinForms 深度嵌套控件调整内核大小错误 - 拆分器面板无法正确缩放控件

标签 vb.net winforms windows-kernel

(最初对 nested 的猜测被证明是不正确的。问题似乎是 SplitContainer 面板无法正确缩放其托管控件。)

我有一些表单的选项卡控件在加载时无法正确调整大小。 https://support.microsoft.com/en-us/kb/953934在 2008 年描述了这样一个内核错误。很难相信它还没有被修复。我认为它消失了一段时间,但我开始再次看到问题。

控件嵌套得很深。 Midi 父窗体、子窗体、选项卡控件、带有两个面板和控件的拆分器控件。对于自上而下的第一个有问题的控件是选项卡控件。当表单在加载后调整大小但 anchor 不正确并且部分控件被剪裁时,它会调整大小。

该问题似乎特定于 100% 桌面字体大小 - 具有 100+ 大小的桌面可以正常工作。我使用 VS 2013 v5 以 125% 的速度开发 - 这个问题也出现在 v4 上。

任何人都知道缺少知识库文章中概述的自定义控件的工作吗?

还有什么我错过了?

更仔细地观察它,SplitContainer 是不调整大小/尊重 anchor 的控件。

我尝试在显示选项卡后运行此代码,但它不起作用 - 看起来与使用 anchor 大致相同。似乎 TabControl 报告了不正确的 ClientSize

    SplitContainer1.Width = TabControl1.ClientSize.Width - 10
    SplitContainer1.Height = TabControl1.ClientSize.Height - TabControl1.ItemSize.Height - 10

这是显示问题的完整表格。在 125% 桌面上,它在 IDE 中显示为 100% 桌面上的选项卡上的控件未正确定位。
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmChild
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<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

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.TabControl1 = New System.Windows.Forms.TabControl()
    Me.TabPage1 = New System.Windows.Forms.TabPage()
    Me.SplitContainer1 = New System.Windows.Forms.SplitContainer()
    Me.Button1 = New System.Windows.Forms.Button()
    Me.TabPage2 = New System.Windows.Forms.TabPage()
    Me.TextBox1 = New System.Windows.Forms.TextBox()
    Me.Button2 = New System.Windows.Forms.Button()
    Me.TabControl1.SuspendLayout()
    Me.TabPage1.SuspendLayout()
    CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SplitContainer1.Panel1.SuspendLayout()
    Me.SplitContainer1.Panel2.SuspendLayout()
    Me.SplitContainer1.SuspendLayout()
    Me.SuspendLayout()
    '
    'TabControl1
    '
    Me.TabControl1.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.TabControl1.Controls.Add(Me.TabPage1)
    Me.TabControl1.Controls.Add(Me.TabPage2)
    Me.TabControl1.Location = New System.Drawing.Point(82, 2)
    Me.TabControl1.Name = "TabControl1"
    Me.TabControl1.SelectedIndex = 0
    Me.TabControl1.Size = New System.Drawing.Size(466, 436)
    Me.TabControl1.TabIndex = 2
    '
    'TabPage1
    '
    Me.TabPage1.Controls.Add(Me.SplitContainer1)
    Me.TabPage1.Location = New System.Drawing.Point(4, 25)
    Me.TabPage1.Name = "TabPage1"
    Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
    Me.TabPage1.Size = New System.Drawing.Size(458, 407)
    Me.TabPage1.TabIndex = 0
    Me.TabPage1.Text = "TabPage1"
    Me.TabPage1.UseVisualStyleBackColor = True
    '
    'SplitContainer1
    '
    Me.SplitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
    Me.SplitContainer1.Location = New System.Drawing.Point(3, 3)
    Me.SplitContainer1.Name = "SplitContainer1"
    Me.SplitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal
    '
    'SplitContainer1.Panel1
    '
    Me.SplitContainer1.Panel1.Controls.Add(Me.Button2)
    Me.SplitContainer1.Panel1.Controls.Add(Me.TextBox1)
    '
    'SplitContainer1.Panel2
    '
    Me.SplitContainer1.Panel2.Controls.Add(Me.Button1)
    Me.SplitContainer1.Size = New System.Drawing.Size(452, 401)
    Me.SplitContainer1.SplitterDistance = 223
    Me.SplitContainer1.TabIndex = 0
    '
    'Button1
    '
    Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.Button1.Location = New System.Drawing.Point(371, 146)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(75, 23)
    Me.Button1.TabIndex = 0
    Me.Button1.Text = "Button1"
    Me.Button1.UseVisualStyleBackColor = True
    '
    'TabPage2
    '
    Me.TabPage2.Location = New System.Drawing.Point(4, 25)
    Me.TabPage2.Name = "TabPage2"
    Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
    Me.TabPage2.Size = New System.Drawing.Size(854, 450)
    Me.TabPage2.TabIndex = 1
    Me.TabPage2.Text = "TabPage2"
    Me.TabPage2.UseVisualStyleBackColor = True
    '
    'TextBox1
    '
    Me.TextBox1.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.TextBox1.BackColor = System.Drawing.SystemColors.Info
    Me.TextBox1.Location = New System.Drawing.Point(17, 13)
    Me.TextBox1.Multiline = True
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
    Me.TextBox1.Size = New System.Drawing.Size(344, 177)
    Me.TextBox1.TabIndex = 0
    '
    'Button2
    '
    Me.Button2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.Button2.Location = New System.Drawing.Point(371, 195)
    Me.Button2.Name = "Button2"
    Me.Button2.Size = New System.Drawing.Size(75, 23)
    Me.Button2.TabIndex = 1
    Me.Button2.Text = "Button2"
    Me.Button2.UseVisualStyleBackColor = True
    '
    'frmChild
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(120.0!, 120.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
    Me.ClientSize = New System.Drawing.Size(548, 439)
    Me.Controls.Add(Me.TabControl1)
    Me.Name = "frmChild"
    Me.Text = "frmChild"
    Me.TabControl1.ResumeLayout(False)
    Me.TabPage1.ResumeLayout(False)
    Me.SplitContainer1.Panel1.ResumeLayout(False)
    Me.SplitContainer1.Panel1.PerformLayout()
    Me.SplitContainer1.Panel2.ResumeLayout(False)
    CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
    Me.SplitContainer1.ResumeLayout(False)
    Me.ResumeLayout(False)

End Sub
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class

最佳答案

如果 SplitPanel没有正确锚定其内容,您可以尝试将内容放入另一个错误较少的容器中。

试着把 TableLayoutPanel里面SplitPanel .设置TableLayoutPanel.Dock属性(property)给 Fill ,然后是 .Anchor你在里面的控件。 (不要在 .Dock 中使用 TableLayoutPanel ,这有点不稳定)。
TableLayoutPanel 中的控件将有名为 .RowSpan 的新属性和 .ColumnSpan这允许控件跨越多个单元格。
TableLayoutPanel 的右上角有一个小箭头这将允许您编辑行和列。我发现最好的办法是制作尽可能多的固定宽度/高度,然后使用百分比其余部分。我不使用 Autosize但你可以试试。

关于vb.net - WinForms 深度嵌套控件调整内核大小错误 - 拆分器面板无法正确缩放控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31682487/

相关文章:

vb.net - 来自字节数组的图像

c# - 带有数据库发布的 Windows 窗体应用程序

c# - 为什么具有泛型类型的基本 Windows 窗体窗体类会停止设计器加载?

windows - 为什么 Windows 在内核中处理滚动条?

windows-kernel - 从 Windows 子系统为 Linux 进程调用 Win32/NT-Native API?

c++ - 如何在 VB.net 中包含/导入 C++ 应用程序

vb.net - 在 Visual Basic 中检查 Bitlocker 加密状态

c# - 需要通过 .NET 代码传真 HTML

c# - WinForm 绑定(bind)单选按钮

visual-c++ - Windows 桌面在繁重的网络 I/O 期间变得瘫痪/Windows 内核仅分配了众多 CPU 中的 1 个?