Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Windows Forms
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
Posted 17-Apr-12 4:06am

1 solution

Rate this: bad
good
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[^]
 
[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]
  Permalink  
v2
Comments
BobishKindaGuy at 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 at 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 at 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 at 7-Nov-12 2:06am
   
Hey! See my updated answer.
Have a nice day!
BobishKindaGuy at 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
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2014
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