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
http://www.microsoft.com/downloads/details.aspx?FamilyId=A8F5654F-088E-40B2-BBDB-A83353618B38

狀況說明

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. 文字方塊 控制項加入至 [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 On
      Option 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 Region
      
      End Class
      
    9. 在 [方案總管] 中 user_control_scroll_UI] 上按一下滑鼠右鍵,並指向 [新增,然後按一下 [加入新項目

      出現 [加入新項目-user_control_scroll_UI] 對話方塊。
    10. 在 [名稱] 方塊中輸入 Mdi.vb,然後按一下 [開啟舊檔]。

      名為 Mdi.vb 的檔案就會出現。
    11. 在 [方案總管] 中,名為 Mdi.vb,在表單上按一下滑鼠右鍵,然後按一下 [檢視程式碼
    12. 現有的程式碼取代下列程式碼:
      Option Strict On
      Option 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 Sub
      End Class
      
    13. 在 [方案總管] 中 user_control_scroll_UI] 上按一下滑鼠右鍵,並指向 [新增,然後按一下 [加入新項目

      出現 [加入新項目-user_control_scroll_UI] 對話方塊。
    14. 在 [名稱] 方塊中輸入 Vscroll.vb,然後按一下 [開啟舊檔]。

      名為 Vscroll.vb 的檔案就會出現。
    15. 在 [方案總管] 中,名為 Vscroll.vb,在表單上按一下滑鼠右鍵,然後按一下 [檢視程式碼
    16. 現有的程式碼取代下列程式碼:
      ption Strict On
      Option 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 Sub
      
      End 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 開發 o 人 h 員 ? 工 u 具 ? 網路 (MSDN) 網站:
http://msdn2.microsoft.com/en-us/library/aa984329(VS.71).aspx
如需詳細資訊按一下 [下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項]:
824684用來描述 Microsoft 軟體更新標準術語的說明

屬性

文章編號: 839577 - 上次校閱: 2007年5月18日 - 版次: 2.2
這篇文章中的資訊適用於:
  • Microsoft .NET Framework 1.1
關鍵字:?
kbmt kbqfe kbhotfixserver kbmdi kbnetframe110sp1fix kbscrollbar kbcontrol kbforms kbbug kbfix kbnetframe110presp1fix KB839577 KbMtzh
機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:839577
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。

提供意見

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com