Click here to Skip to main content
15,892,059 members

Scrollbar on panel seems to work strangely

bobishkindaguy asked:

Open original thread
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.)


VB
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
Tags: Visual Basic, Windows, Forms

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900