Click here to Skip to main content
13,252,206 members (55,874 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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()
  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.AutoScroll = True
    Me.pnlAutoScrollTest.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    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
    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
    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
    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
    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
    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
    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.Name = "Form1"
    Me.Text = "What !!??"
  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
Posted 17-Apr-12 4:06am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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[^]

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.
BobishKindaGuy 5-Nov-12 9:44am
Oh, my instructions for creating this project didn't include the following:
Please open the designer code window and delete the auto-generated code from that window before running the project.
You will see the problem then.
Maciej Los 5-Nov-12 13:44pm
I do not need these instruction. I've successfuly created a form and i see what is going on. I don't get your idea... Please, explain what are trying to achieve moving TextBox to the left inside the Panel.
BobishKindaGuy 6-Nov-12 18:24pm
The textbox could be a panel or any other control. I probably should have used a panel. This is for a wizard window. Usually the user clicks "Back" or "Next" to make the screens of the wizard come into view.
I wanted to allow the user to scroll a row of panels left and right, so they had a choice of using the scroll bar or the Back and Next buttons.
If you use the button to make the textbox go out of sight to the right, the scroll bar appears. But if you use the button to make the textbox go out of sight to the left, the scrollbar does not appear. I believe it should, though.
Maciej Los 7-Nov-12 2:06am
Hey! See my updated answer.
Have a nice day!
BobishKindaGuy 7-Nov-12 12:56pm
Thanks for your suggestions, Maciej.
I know how to do wizard windows, but my post was intended to demonstrate that the AutoScroll property doesn't work properly, unless I am missing something.
Content scrolls out of view all the time, both to the left or right. In the window you are now viewing, content is scrolled up out of sight, and you can use the scroll bar to bring it back. The AutoScroll property should work similarly to manage content horizontally.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100