面板上的滚动条似乎工作异常 [英] Scrollbar on panel seems to work strangely

查看:65
本文介绍了面板上的滚动条似乎工作异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么滚动条仅在控件从面板右侧移出视图而不在左侧移出视图时起作用?

只需在VB中创建一个Windows窗体应用程序,然后将以下代码粘贴到Form1的代码窗口中即可. (该代码包括设计器代码,因此可以正确创建所有控件.)


Why does the scrollbar only work when the control moves out of view on the RIGHT of the panel but not on the LEFT?

Just make a windows forms application in VB, and paste the following code into the code window of Form1. (The code includes the designer code so all controls get created properly.)


Public Class Form1
  Inherits System.Windows.Forms.Form
  Public Sub New()
    InitializeComponent()
  End Sub

  Private Sub btnMoveLeft_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveLeft.Click
    TextBox1.Left -= 10
  End Sub

  Private Sub btnMoveRight_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveRight.Click
    TextBox1.Left += 10
  End Sub

  Private Sub btnBigger_Click(sender As System.Object, e As System.EventArgs) Handles btnBigger.Click
    TextBox1.Width += 10
  End Sub

  Private Sub btnSmaller_Click(sender As System.Object, e As System.EventArgs) Handles btnSmaller.Click
    If TextBox1.Width > 10 Then TextBox1.Width -= 10
  End Sub

#Region "Designer items"
  Private components As System.ComponentModel.IContainer
  Private Sub InitializeComponent()
    Me.pnlAutoScrollTest = New System.Windows.Forms.Panel()
    Me.btnMoveLeft = New System.Windows.Forms.Button()
    Me.btnMoveRight = New System.Windows.Forms.Button()
    Me.TextBox1 = New System.Windows.Forms.TextBox()
    Me.btnBigger = New System.Windows.Forms.Button()
    Me.btnSmaller = New System.Windows.Forms.Button()
    Me.pnlAutoScrollTest.SuspendLayout()
    Me.SuspendLayout()
    '
    'pnlAutoScrollTest
    '
    Me.pnlAutoScrollTest.AutoScroll = True
    Me.pnlAutoScrollTest.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.pnlAutoScrollTest.Controls.Add(Me.TextBox1)
    Me.pnlAutoScrollTest.Location = New System.Drawing.Point(12, 12)
    Me.pnlAutoScrollTest.Name = "pnlAutoScrollTest"
    Me.pnlAutoScrollTest.Size = New System.Drawing.Size(210, 100)
    Me.pnlAutoScrollTest.TabIndex = 0
    '
    'btnMoveLeft
    '
    Me.btnMoveLeft.Location = New System.Drawing.Point(12, 130)
    Me.btnMoveLeft.Name = "btnMoveLeft"
    Me.btnMoveLeft.Size = New System.Drawing.Size(102, 23)
    Me.btnMoveLeft.TabIndex = 1
    Me.btnMoveLeft.Text = "<< move left"
    Me.btnMoveLeft.UseVisualStyleBackColor = True
    '
    'btnMoveRight
    '
    Me.btnMoveRight.Location = New System.Drawing.Point(120, 130)
    Me.btnMoveRight.Name = "btnMoveRight"
    Me.btnMoveRight.Size = New System.Drawing.Size(102, 23)
    Me.btnMoveRight.TabIndex = 1
    Me.btnMoveRight.Text = "move right >>"
    Me.btnMoveRight.UseVisualStyleBackColor = True
    '
    'TextBox1
    '
    Me.TextBox1.Location = New System.Drawing.Point(22, 35)
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.Size = New System.Drawing.Size(167, 20)
    Me.TextBox1.TabIndex = 0
    '
    'btnBigger
    '
    Me.btnBigger.Location = New System.Drawing.Point(67, 169)
    Me.btnBigger.Name = "btnBigger"
    Me.btnBigger.Size = New System.Drawing.Size(100, 23)
    Me.btnBigger.TabIndex = 2
    Me.btnBigger.Text = "<< Bigger >>"
    Me.btnBigger.UseVisualStyleBackColor = True
    '
    'btnSmaller
    '
    Me.btnSmaller.Location = New System.Drawing.Point(67, 198)
    Me.btnSmaller.Name = "btnSmaller"
    Me.btnSmaller.Size = New System.Drawing.Size(100, 23)
    Me.btnSmaller.TabIndex = 2
    Me.btnSmaller.Text = ">> Smaller <<"
    Me.btnSmaller.UseVisualStyleBackColor = True
    '
    'Form1
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(232, 237)
    Me.Controls.Add(Me.btnSmaller)
    Me.Controls.Add(Me.btnBigger)
    Me.Controls.Add(Me.btnMoveRight)
    Me.Controls.Add(Me.btnMoveLeft)
    Me.Controls.Add(Me.pnlAutoScrollTest)
    Me.Name = "Form1"
    Me.Text = "What !!??"
    Me.pnlAutoScrollTest.ResumeLayout(False)
    Me.pnlAutoScrollTest.PerformLayout()
    Me.ResumeLayout(False)

  End Sub
  Friend WithEvents pnlAutoScrollTest As System.Windows.Forms.Panel
  Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  Friend WithEvents btnMoveLeft As System.Windows.Forms.Button
  Friend WithEvents btnMoveRight As System.Windows.Forms.Button
  Friend WithEvents btnBigger As System.Windows.Forms.Button
  Friend WithEvents btnSmaller As System.Windows.Forms.Button

#End Region
End Class

推荐答案

没有什么奇怪的...

如果控件的Left属性小于零,您是否不能禁用将控件向面板内移动?您想实现什么?

如果我对您的理解很好,则需要使用 AutoScrollMargin [ ^ ] 财产.请仔细阅读以上文章和相关主题.

可能也会有所帮助:检测滚动区域 [ ^ ]

[更新]
如果您想知道如何设计向导表单-请参阅 [ ^ ].
前两个示例:
以设计者为中心的向导控件 [ .NET向导控件 [ TabControl [
There''s nothing strange...

Can''t you just disable to move a control left inside Panel, if its Left property is less then zero? What do you want to achieve?

If i understand you well, you need to use AutoScrollMargin[^] property. Read carefully above article and related topics.

It might be helpful too: Detecting scroll area[^]

[update]
If you want to know how to design wizard form - see this[^].
First 2 examples:
Designer centric Wizard control[^]
A .NET Wizard control[^]

You can use TabControl[^] and Next and Previous button to toggle between tabs.
[/update]


这篇关于面板上的滚动条似乎工作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆