Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vertical Scroll Bar & Frame

Status
Not open for further replies.

Madman37

Programmer
Apr 1, 2004
6
GB
I am using Visual Baisc to create a programme that has two frames and 100 text boxes (99 of which are created at run time.) The first frame is ProductFrame and the second is called InnerFrame (which sits inside Product Frame). My problem is that when I scroll with the scroll bar, the frame moves and not the contents. How do I make the contents move and not the Frame? Text1(0) has been drawn on the frame. My code is below:

Private Sub Form_Load()
Dim i, previousI As Integer

' VScroll.Max = 200
' cmboCount / 15
' VScroll.Min = 0
' VScroll.Top = 0
' VScroll.Left = InnerFrame.Width
' VScroll.Height = InnerFrame.Height
' VScroll.Visible = True

noItems = 100

For i = 1 To noItems
Load Text1(i)
Set Text1(i).Container = InnerFrame
perviousI = i - 1
newTop = Text1(perviousI).Top + 300
Text1(i).Top = newTop
Text1(i).Visible = True
Text1(i).Text = i
Next
Set InnerFrame.Container = productsFrame
End Sub

Private Sub VScroll_Change()
Dim tempInt As Integer
tempInt = 20
' productsFrame.Top = -tempInt * VScroll.Value
InnerFrame.Top = -tempInt * VScroll.Value
' InnerFrame.Top = -VScroll.Value
' Move InnerFrame.Top - tempInt
' Move productsFrame.Top = tempInt * VScroll.Value
End Sub

Private Sub Form_Unload(Cancel As Integer)
' Unload Me
customerRecords.Close

For i = 1 To noItems
Unload Text1(i)
Next
' End
End Sub


 

Welcome to TT Madman37! To get the most from these fora please read FAQ222-2244.

To make the contents move you will have to set/reset their values with each change of the scrollbar.

Good Luck

 
Thnak you vb5prgrmr for your prompt reply.

When you say "set/reset their values" could you give me more and if possible some example code?
 

Yes that is one way to accomplish what you want but let me clarify exactly what you are trying to do...FAQ222-2244

Give this a try... you will need a verticle scroll bar named VS and a text box named TB with its index set to 0
[tt]
Private Sub Form_Load()

Dim I As Integer

VS.Left = Me.ScaleWidth - (VS.Width + 30)
VS.Top = 30
VS.Height = Me.ScaleHeight - 30

For I = 1 To 19
Load TB(I)
TB(I).Top = TB(I - 1).Top + 360
TB(I).Left = TB(0).Left
TB(I).Visible = True
TB(I).Text = I
Next I
TB(0).Text = 0

VS.Max = (20 - 9) 'number of textboxes show on my form
VS.TabIndex = 1000

End Sub

Private Sub VS_Change()

Dim I As Integer

TB(0).Top = 30 + (VS.Value * -360)

For I = 1 To 19
TB(I).Top = TB(I - 1).Top + 360
Next I

End Sub
[/tt]

Now if you are doing something like this for 100 text boxes I would suggest that you use picturebox/frame idea from the thread you pointed out so you do not run into any overflow errors.

Good Luck


 
Sorry I have not been in touch. Thank you once again for all your help. Your frame code works well apart from one line: VS.Height = Me.ScaleHeight - 30.

The code means the scroll bar does not display, however when this line is commented out the scroll bar displays why is this?

I was also wondering what is the purpose of the value 30 as defined in the following lines of code:
VS.Left = Me.ScaleWidth - (VS.Width + 30)
TB(0).Top = 30 + (VS.Value * -360)?

Many Thanks :)
 
Hello Madman37,

I think I have the same problem with a scrollbar as you do: sometimes mine does not display after setting some of it's values. I have not been able to figure out exactly when it does this and I have no idea why it does so. I keep looking for a solution and I'll post it when I find it. Meanwhile, do you have new insights into the situation?

Hokje


when there's too much something is missing
 
Yes, the above code that has bene proveded does work. My scroll bar did nto display when used the following code: VS.Height = Me.ScaleHeight - 30. I think it is best nto to set the height of the scroll bar in the code, but make sure the height is right at design time. Let me look at the code, and I will see what I can do if you want me to?
 
Ok, that helps me a little. The problem is that I have to set the scrollbar's height in code in the _resize event. It disappears when the form my scrollbar is on is resized. Can't do without resizing the scrollbar...

Have you figured out at what values it disappears/doesn't display? If you could tell me that I'd get a start at fixing my problem!

tanx, Hokje
 
I have not yet figured out, what values, but the only thing I cna think is that the scroll bar needs to be samller in height than its container. Container can be a frame or a form.
 
I can't find anything wrong with my resizing code. If the scroll bar disappears when its container is smaller it should disappear everytime I resize my form (this causes the container to resize and then the scrollbar to resize). I have a temporal 'fix' which is to NOT let the user resize the form vertically, so that neither the scrollbar's or its container's height is reset. This seems to have solved my problem.

 

Ok, this code...
[tt]
VS.Left = Me.ScaleWidth - (VS.Width + 30)
VS.Top = 30
VS.Height = Me.ScaleHeight - 30
[/tt]
In form load tells the vertical scroll bar where it should be displayed when its window is drawn. The 30 that you are asking about allows enough room for the 3D effects of the control to be displayed. If you leave them out it looks like the scroll bar is running off of the form.

Now this code...
[tt]
TB(0).Top = 30 + (VS.Value * -360)

For I = 1 To 19
TB(I).Top = TB(I - 1).Top + 360
Next I
[/tt]
pretty much does the same thing. It allows the text box 3D effects to be drawn so it does not look like it is running off of the form.

Granted the form I used had the default setting of twips for its scalemode. If you change those settings to say pixel you will need to figure out a different setting from 30. More like 1 or 2 to allow the 3D effects to be drawn correctly.

So that is probably why it is not displaying correctly for you and you are right it is to keep the scroll bar just a little smaller than its container.

As for why it is disappearing I don't know without seeing your code. Do you have SP5 installed (or the new SP6) for VB?

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top