FIX: 您不能滚动 MDI 子窗体通过单击向下滚动箭头

注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。

839577
本文已归档。它按“原样”提供,并且不再更新。
症状
多文档界面 (MDI) 子窗体上有一个用户控件时您不能向下滚动。当用户控件包含焦点时,会出现此问题。您试图通过使用子窗体的滚动条上的向下滚动箭头向下滚动,但您不能向下滚动。
原因
当一个用户控件中包含焦点时用户控件是一个活动控件。但是,当该用户控件中包含焦点时 Microsoft.net Framework 1.1 中存在该 ActiveControl.Focused 属性将返回 False 的而不是返回 True。因此,将重点放在用户控件强制窗体,以使用户控件可见。当您通过单击向下滚动箭头来执行滚动的情况下操作时,就会出现此问题。
解决方案
若要解决此问题,获得最新的 service pack,对于在 Microsoft.net Framework 1.1。以下文件是可从 Microsoft 下载中心下载:

Microsoft.net Framework 1.1 Service Pack 1
状态
Microsoft 已经确认这是在"适用于"一节中列出的 Microsoft 产品中的问题。 此问题已被首先更正在 Microsoft.net Framework 1.1 Service Pack 1。
更多信息

重现此问题的步骤

  1. 创建用户控件文件。若要这样做,请按照下列步骤操作:
    1. 启动 Microsoft Visual Studio.net。
    2. 文件 菜单上指向 新建,然后单击 项目

      新建项目 对话框。
    3. 项目类型 框中,单击 Visual Basic 项目
    4. 模板 框中,单击 Windows 控件库
    5. 名称 框中键入 testusercontrol,然后单击 确定

      默认状态下,该文件,名为 Usercontrol1.vb 出现。
    6. TextBox 控件添加到该 Usercontrol1.vb [设计] 文件。
    7. 生成 菜单上单击 生成解决方案
  2. 添加到项目的 Windows 应用程序。若要这样做,请按照下列步骤操作:
    1. 文件 菜单上指向 添加项目,然后单击 新建项目

      新建项目 对话框。
    2. 项目类型 框中,单击 Visual 基本的项目
    3. 模板 框中,单击 Windows 应用程序
    4. 名称 框中键入 user_control_scroll_UI,然后单击 确定

      默认状态下,将出现名为 Form1 的窗体。
    5. 在解决方案资源管理器中,用鼠标右键单击 user_control_scroll_UI,然后单击 添加引用

      添加引用 对话框。
    6. 单击 项目 选项卡并单击 选择,然后单击 确定 以将该 testusercontrol 添加到您的项目引用。
    7. 用鼠标右键单击名为 Form1 的窗体,然后单击 视图代码
    8. 将现有代码替换下面的代码:
      Option Strict OnOption Explicit On Public Class MDIChild    Inherits System.Windows.Forms.Form#Region " Windows Forms Designer generated code "    Public Sub New()        MyBase.New()        'This call is required by the Windows Forms Designer.        InitializeComponent()        'Add any initialization after the InitializeComponent() call.    End Sub    'The Form overrides dispose to clean up the component list.    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)        If disposing Then            If Not (components Is Nothing) Then                components.Dispose()            End If        End If        MyBase.Dispose(disposing)    End Sub    'This is required by the Windows Forms Designer.    Private components As System.ComponentModel.IContainer    'Note The following procedure is required by the Windows Forms Designer.    'The following procedure can be modified by using the Windows Forms Designer.      'Do not modify the following procedure by using the code editor.    Friend WithEvents UserControl11 As testusercontrol.UserControl1    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox    Friend WithEvents TextBox5 As System.Windows.Forms.TextBox    Friend WithEvents TextBox6 As System.Windows.Forms.TextBox    Friend WithEvents UserControl12 As testusercontrol.UserControl1    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()        Me.UserControl11 = New testusercontrol.UserControl1        Me.TextBox1 = New System.Windows.Forms.TextBox        Me.TextBox2 = New System.Windows.Forms.TextBox        Me.TextBox3 = New System.Windows.Forms.TextBox        Me.TextBox4 = New System.Windows.Forms.TextBox        Me.TextBox5 = New System.Windows.Forms.TextBox        Me.TextBox6 = New System.Windows.Forms.TextBox        Me.UserControl12 = New testusercontrol.UserControl1        Me.SuspendLayout()        '        'UserControl11        '        Me.UserControl11.Location = New System.Drawing.Point(26, 30)        Me.UserControl11.Name = "UserControl11"        Me.UserControl11.Size = New System.Drawing.Size(104, 24)        Me.UserControl11.TabIndex = 0        '        'TextBox1        '        Me.TextBox1.Location = New System.Drawing.Point(26, 161)        Me.TextBox1.Name = "TextBox1"        Me.TextBox1.TabIndex = 1        Me.TextBox1.Text = "TextBox1"        '        'TextBox2        '        Me.TextBox2.Location = New System.Drawing.Point(26, 384)        Me.TextBox2.Name = "TextBox2"        Me.TextBox2.Size = New System.Drawing.Size(103, 20)        Me.TextBox2.TabIndex = 2        Me.TextBox2.Text = "TextBox2"        '        'TextBox3        '        Me.TextBox3.Location = New System.Drawing.Point(26, 541)        Me.TextBox3.Name = "TextBox3"        Me.TextBox3.TabIndex = 3        Me.TextBox3.Text = "TextBox3"        '        'TextBox4        '        Me.TextBox4.Location = New System.Drawing.Point(26, 725)        Me.TextBox4.Name = "TextBox4"        Me.TextBox4.TabIndex = 4        Me.TextBox4.Text = "TextBox4"        '        'TextBox5        '        Me.TextBox5.Location = New System.Drawing.Point(26, 929)        Me.TextBox5.Name = "TextBox5"        Me.TextBox5.TabIndex = 5        Me.TextBox5.Text = "TextBox5"        '        'TextBox6        '        Me.TextBox6.Location = New System.Drawing.Point(26, 1394)        Me.TextBox6.Name = "TextBox6"        Me.TextBox6.TabIndex = 7        Me.TextBox6.Text = "TextBox6"        '        'UserControl12        '        Me.UserControl12.Location = New System.Drawing.Point(26, 1142)        Me.UserControl12.Name = "UserControl12"        Me.UserControl12.Size = New System.Drawing.Size(103, 27)        Me.UserControl12.TabIndex = 6        '        'MDIChild        '        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)        Me.AutoScroll = True        Me.ClientSize = New System.Drawing.Size(275, 266)        Me.Controls.Add(Me.UserControl12)        Me.Controls.Add(Me.TextBox6)        Me.Controls.Add(Me.TextBox5)        Me.Controls.Add(Me.TextBox4)        Me.Controls.Add(Me.TextBox3)        Me.Controls.Add(Me.TextBox2)        Me.Controls.Add(Me.TextBox1)        Me.Controls.Add(Me.UserControl11)        Me.Name = "MDIChild"        Me.Text = "MDIChild"        Me.ResumeLayout(False)    End Sub#End RegionEnd Class
    9. 在解决方案资源管理器中,用鼠标右键单击 user_control_scroll_UI,指向 添加,然后再单击 添加新项

      添加新项-user_control_scroll_UI 对话框。
    10. 名称 框中键入 Mdi.vb,然后单击 打开

      该文件,名为 Mdi.vb 出现。
    11. 在解决方案资源管理器中,用鼠标右键单击名为 Mdi.vb 的窗体,然后单击 查看代码
    12. 将现有代码替换下面的代码:
      Option Strict OnOption Explicit On Public Class MDI    Inherits System.Windows.Forms.Form#Region " Windows Forms Designer generated code "    Public Sub New()        MyBase.New()        'This call is required by the Windows Forms Designer.        InitializeComponent()        'Add any initialization after the InitializeComponent() call.    End Sub    'The Form overrides dispose to clean up the component list.    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)        If disposing Then            If Not (components Is Nothing) Then                components.Dispose()            End If        End If        MyBase.Dispose(disposing)    End Sub    'This is required by the Windows Forms Designer.    Private components As System.ComponentModel.IContainer    'Note The following procedure is required by the Windows Forms Designer    'The following procedure can be modified by using the Windows Forms Designer.      'Do not modify the following procedure by using the code editor.    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu    Friend WithEvents mnuAutoScroll As System.Windows.Forms.MenuItem    Friend WithEvents mnuVScroll As System.Windows.Forms.MenuItem    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()        Me.MainMenu1 = New System.Windows.Forms.MainMenu        Me.mnuAutoScroll = New System.Windows.Forms.MenuItem        Me.mnuVScroll = New System.Windows.Forms.MenuItem        '        'MainMenu1        '        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuAutoScroll, Me.mnuVScroll})        '        'mnuAutoScroll        '        Me.mnuAutoScroll.Index = 0        Me.mnuAutoScroll.Text = "Load AutoScroll Child"        '        'mnuVScroll        '        Me.mnuVScroll.Index = 1        Me.mnuVScroll.Text = "Load VScroll Child"        '        'MDI        '        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)        Me.ClientSize = New System.Drawing.Size(366, 299)        Me.IsMdiContainer = True        Me.Menu = Me.MainMenu1        Me.Name = "MDI"        Me.Text = "MDI"    End Sub#End Region    Private Sub MDI_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load    End Sub    Private Sub mnuAutoScroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAutoScroll.Click        Dim currentForm As New MDIChild        currentForm.MdiParent = Me        currentForm.WindowState = FormWindowState.Maximized        currentForm.Show()        currentForm.BringToFront()    End Sub    Private Sub mnuVScroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVScroll.Click        Dim currentForm As New VScrollChild        currentForm.MdiParent = Me        currentForm.WindowState = FormWindowState.Maximized        currentForm.Show()        currentForm.BringToFront()    End SubEnd Class
    13. 在解决方案资源管理器中,用鼠标右键单击 user_control_scroll_UI,指向 添加,然后再单击 添加新项

      添加新项-user_control_scroll_UI 对话框。
    14. 名称 框中键入 Vscroll.vb,然后单击 打开

      该文件,名为 Vscroll.vb 出现。
    15. 在解决方案资源管理器中,用鼠标右键单击名为 Vscroll.vb 的窗体,然后单击 查看代码
    16. 将现有代码替换下面的代码:
      ption Strict OnOption Explicit On Public Class VScrollChild    Inherits System.Windows.Forms.Form#Region " Windows Forms Designer generated code "    Public Sub New()        MyBase.New()        'This call is required by the Windows Forms Designer.        InitializeComponent()        'Add any initialization after the InitializeComponent() call.    End Sub    'The form overrides dispose to clean up the component list.    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)        If disposing Then            If Not (components Is Nothing) Then                components.Dispose()            End If        End If        MyBase.Dispose(disposing)    End Sub    'This is required by the Windows Forms Designer.    Private components As System.ComponentModel.IContainer    'Note The following procedure is required by the Windows Forms Designer.    'The following procedure can be modified by using the Windows Forms Designer.      'Do not modify the following procedure by using the code editor.    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox    Friend WithEvents TextBox5 As System.Windows.Forms.TextBox    Friend WithEvents TextBox6 As System.Windows.Forms.TextBox    Friend WithEvents testUcNum1 As testusercontrol.UserControl1    Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar    Friend WithEvents testUcNum2 As testusercontrol.UserControl1    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()        Me.testUcNum1 = New testusercontrol.UserControl1        Me.TextBox1 = New System.Windows.Forms.TextBox        Me.TextBox2 = New System.Windows.Forms.TextBox        Me.TextBox3 = New System.Windows.Forms.TextBox        Me.TextBox4 = New System.Windows.Forms.TextBox        Me.TextBox5 = New System.Windows.Forms.TextBox        Me.TextBox6 = New System.Windows.Forms.TextBox        Me.VScrollBar1 = New System.Windows.Forms.VScrollBar        Me.testUcNum2 = New testusercontrol.UserControl1        Me.SuspendLayout()        '        'testUcNum1        '        Me.testUcNum1.Location = New System.Drawing.Point(26, 30)        Me.testUcNum1.Name = "testUcNum1"        Me.testUcNum1.Size = New System.Drawing.Size(104, 24)        Me.testUcNum1.TabIndex = 0        '        'TextBox1        '        Me.TextBox1.Location = New System.Drawing.Point(26, 161)        Me.TextBox1.Name = "TextBox1"        Me.TextBox1.TabIndex = 1        Me.TextBox1.Text = "TextBox1"        '        'TextBox2        '        Me.TextBox2.Location = New System.Drawing.Point(26, 384)        Me.TextBox2.Name = "TextBox2"        Me.TextBox2.Size = New System.Drawing.Size(103, 20)        Me.TextBox2.TabIndex = 2        Me.TextBox2.Text = "TextBox2"        '        'TextBox3        '        Me.TextBox3.Location = New System.Drawing.Point(26, 541)        Me.TextBox3.Name = "TextBox3"        Me.TextBox3.TabIndex = 3        Me.TextBox3.Text = "TextBox3"        '        'TextBox4        '        Me.TextBox4.Location = New System.Drawing.Point(26, 725)        Me.TextBox4.Name = "TextBox4"        Me.TextBox4.TabIndex = 4        Me.TextBox4.Text = "TextBox4"        '        'TextBox5        '        Me.TextBox5.Location = New System.Drawing.Point(26, 929)        Me.TextBox5.Name = "TextBox5"        Me.TextBox5.TabIndex = 5        Me.TextBox5.Text = "TextBox5"        '        'TextBox6        '        Me.TextBox6.Location = New System.Drawing.Point(26, 1394)        Me.TextBox6.Name = "TextBox6"        Me.TextBox6.TabIndex = 7        Me.TextBox6.Text = "TextBox6"        '        'VScrollBar1        '        Me.VScrollBar1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)        Me.VScrollBar1.Location = New System.Drawing.Point(224, 0)        Me.VScrollBar1.Name = "VScrollBar1"        Me.VScrollBar1.Size = New System.Drawing.Size(17, 266)        Me.VScrollBar1.TabIndex = 8        '        'testUcNum2        '        Me.testUcNum2.Location = New System.Drawing.Point(27, 639)        Me.testUcNum2.Name = "testUcNum2"        Me.testUcNum2.Size = New System.Drawing.Size(104, 24)        Me.testUcNum2.TabIndex = 9        '        'VScrollChild        '        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)        Me.ClientSize = New System.Drawing.Size(241, 266)        Me.Controls.Add(Me.testUcNum2)        Me.Controls.Add(Me.VScrollBar1)        Me.Controls.Add(Me.TextBox6)        Me.Controls.Add(Me.TextBox5)        Me.Controls.Add(Me.TextBox4)        Me.Controls.Add(Me.TextBox3)        Me.Controls.Add(Me.TextBox2)        Me.Controls.Add(Me.TextBox1)        Me.Controls.Add(Me.testUcNum1)        Me.Name = "VScrollChild"        Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show        Me.Text = "MDIChild"        Me.ResumeLayout(False)    End Sub#End Region    Private htControlTops As New Hashtable    'Note The following assumes that no controls are put above the form the first time. For example, there are no negative .Top values.    '      If this is not the case, a similar "topLine" variable is required to make sure that     '      you know the full length of the useful area of the form.    '                            bottomMostCtl.Top + bottomMostCtl.Height - topMostCtl.Top    '      This calculation is not required on this form.    Private bottomLine As Integer = Integer.MinValue    Private Sub MDIChild_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load        For Each ctl As Control In Me.Controls            If TypeOf ctl Is testusercontrol.UserControl1 _                OrElse TypeOf ctl Is TextBox Then                htControlTops.Add(ctl.Name, ctl.Top)                Debug.WriteLine("MDIChild_Load => Ctl Name: " & ctl.Name & ", Top=" & ctl.Top)                If (ctl.Top + ctl.Height) > bottomLine Then                    bottomLine = ctl.Top + ctl.Height                End If            End If        Next    End Sub    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll        Debug.WriteLine("*** VScrollBar1_Scroll event fired! (New Value: " & e.NewValue & ")")        ScrollForMe(e.NewValue)    End Sub    Private Sub ScrollForMe(ByVal scrollValue As Integer)        Dim oldTop As Integer        Dim pct As Double = scrollValue / VScrollBar1.Maximum        'Debug.WriteLine(">>> Percentage Scroll: " & Format(pct, "00.0%") & " <<<")        Dim incr As Integer = CInt(pct * bottomLine)        'Debug.WriteLine(">>> Increment value: " & incr & " <<<")        For Each ctl As Control In Me.Controls            If TypeOf ctl Is testusercontrol.UserControl1 _                OrElse TypeOf ctl Is TextBox Then                oldTop = CType(htControlTops(ctl.Name), Integer)                ctl.Top = oldTop - incr                'Debug.WriteLine("VScrollBar1_Scroll => Ctl Name: " & ctl.Name & ", Top=" & ctl.Top)            End If        Next    End SubEnd Class
  3. 构建在的解决方案,然后运行该项目。若要这样做,请按照下列步骤操作:
    1. 在解决方案资源管理器中,单击 解决方案 testusercontrol (2 个项目)
    2. 项目 菜单上单击 属性

      解决方案 testusercontrol 属性页,将出现对话框。
    3. 在左窗格中双击 通用属性,下的 启动项目,然后单击 $ user_control_scroll_UI
    4. 在左窗格中双击 通用属性 下的 项目依赖项
    5. 在右窗格中单击 testusercontrol项目 列表中,然后单击 确定
    6. 在解决方案资源管理器中,用鼠标右键单击 user_control_scroll_UI,然后单击 属性

      user_control_scroll_UI 属性页,将出现对话框。
    7. 在左窗格中双击 常规 下的 通用属性
    8. 在右窗格中单击 $ 在 启动对象 框中的 MDI
    9. 生成 菜单上单击 生成解决方案
    10. 按 f5 键运行该程序。

      MDI 窗体将显示。
    11. 单击 加载 AutoScroll 子项,单击滚动下拉箭头,以试图在表单中移动。

      您会注意到在"症状"一节中提到的行为。
参考
有关创建 MDI 子窗体的其他信息,请访问下面的 Microsoft 开发人员网络 (MSDN) 的网站:有关更多的信息请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章:
824684用于描述 Microsoft 软件更新的标准术语的说明

警告: 本文已自动翻译

属性

文章 ID:839577 - 上次审阅时间:01/17/2015 08:49:53 - 修订版本: 2.2

  • Microsoft .NET Framework 1.1
  • kbnosurvey kbarchive kbmt kbqfe kbhotfixserver kbmdi kbnetframe110sp1fix kbscrollbar kbcontrol kbforms kbbug kbfix kbnetframe110presp1fix KB839577 KbMtzh
反馈