none
TablControl AutoScroll之問題 RRS feed

  • 一般討論

  • 請問各位專家 :

    我在表單下方佈置StatusStrip  並用Timer使之自動顯示時間

    但我發現一個怪現象 :

    當Timer時間更新時(每秒更新一次)

    TabControl 都會自動跳到游標處

     

    請照下述步驟執行看看

    1.請建新專案 執行下面這段程式碼 表單物件會在Form Load時建立

    2.將TabControl 右方之Scroll Bar 往下拉 可以看到1~4號TextBox

    3.用滑鼠點選4號TextBox  將游標置於其上

    4.此時  若將Scroll Bar 往上拉時 (拉到1號TextBox處)

     當Timer時間更新時TabControl 都會自動下拉  跳到游標處

     

    若未將滑鼠游標置於TextBox上  就不會有此現象

    TabControl之Scroll Bar 也可以任意拉動到任何位置

     

    請問有沒有方法使之不要強制跳到游標處?

    Thanks.

     

    ====================VB2005=====================================================

    Public Class Form3
        Dim Timer As New Timer
        Dim StatusStrip1 = New System.Windows.Forms.StatusStrip
        Dim ToolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel

        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer.Enabled = True
            Timer.Interval = 1000
            AddHandler Timer.Tick, AddressOf Timer_Tick
            '
            Me.Controls.Add(StatusStrip1)
            StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {ToolStripStatusLabel1})
            'With ToolStripStatusLabel1
            '.Name = "ToolStripStatusLabel1"
            '.Size = New System.Drawing.Size(108, 17)
            '.Text = "ToolStripStatusLabel1"
            'End With
            '
            Dim TabControl1 = New System.Windows.Forms.TabControl
            Dim TabPage1 = New System.Windows.Forms.TabPage
            With TabControl1
                .Location = New System.Drawing.Point(4, 4)
                .Size = New System.Drawing.Size(396, 116)
                .Name = "TabControl1"
                .Controls.Add(TabPage1)
            End With
            Me.Controls.Add(TabControl1)
            '
            Dim Label1 = New System.Windows.Forms.Label
            Dim Label2 = New System.Windows.Forms.Label
            Dim Label3 = New System.Windows.Forms.Label
            Dim Label4 = New System.Windows.Forms.Label
            With Label1
                .Location = New System.Drawing.Point(24, 16)
                .Size = New System.Drawing.Size(11, 12)
                .Text = "1"
            End With
            With Label2
                .Location = New System.Drawing.Point(24, 60)
                .Size = New System.Drawing.Size(11, 12)
                .Text = "2"
            End With
            With Label3
                .Location = New System.Drawing.Point(24, 108)
                .Size = New System.Drawing.Size(11, 12)
                .Text = "3"
            End With
            With Label4
                .Location = New System.Drawing.Point(24, 159)
                .Size = New System.Drawing.Size(11, 12)
                .Text = "4"
            End With
            Dim TextBox4 = New System.Windows.Forms.TextBox
            Dim TextBox3 = New System.Windows.Forms.TextBox
            Dim TextBox2 = New System.Windows.Forms.TextBox
            Dim TextBox1 = New System.Windows.Forms.TextBox
            With TextBox4
                .Location = New System.Drawing.Point(60, 152)
                .Size = New System.Drawing.Size(84, 22)
            End With
            With TextBox3
                .Location = New System.Drawing.Point(60, 104)
                .Size = New System.Drawing.Size(84, 22)
            End With
            With TextBox2
                .Location = New System.Drawing.Point(60, 56)
                .Size = New System.Drawing.Size(84, 22)
            End With
            With TextBox1
                .Location = New System.Drawing.Point(60, 12)
                .Size = New System.Drawing.Size(84, 22)
            End With
            '
            With TabPage1
                .AutoScroll = True ' <====
                .Size = New System.Drawing.Size(388, 91)
                .Location = New System.Drawing.Point(4, 21)
                With .Controls
                    .Add(Label4)
                    .Add(Label3)
                    .Add(Label2)
                    .Add(Label1)
                    .Add(TextBox4)
                    .Add(TextBox3)
                    .Add(TextBox2)
                    .Add(TextBox1)
                End With
            End With
        End Sub

        Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
            ToolStripStatusLabel1.Text = Now.ToString()
        End Sub

    End Class

    2008年4月16日 上午 04:34