Can't make the picturebox wide enough?
Hi there folks!
I am working on a number line to teach kids how to skip count numbers. So basically I have a numberline in a picturebox called picPicture. That one is inside another picturebox called picWindow (I got this code off here). : )
So the picturebox scrolls, but the problems is I can't scroll as far as I want.
The number line image file goes from 0-100. The box will only let me scroll up to 39(ish).
Would anyone know of a way to make it scroll to 100?
Thanks!
Here is my code.
VB Code:
Option Explicit
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Martin Liss has no warranty,
' obligations or liability for any Sample Application Files.
Private Sub Form_Activate()
' So that scrooling will happen if the user immediately presses
' PageUp or PageDown
picPicture.SetFocus
End Sub
Private Sub Form_Load()
HScroll1.Width = picWindow.Width
' HScroll1.Max = picPicture.Width - picWindow.Width
HScroll1.SmallChange = 200
HScroll1.LargeChange = picWindow.Width
If picPicture.Picture = 0 Then
lblNoPicture.Visible = True
lblNoPicture.Caption = "Change picPicture's Picture property to refer " _
& "to the location of winnt.bmp (or any large picture)"
End If
End Sub
Public Sub CheckKeyCode(KeyCode As Integer)
'***************************************************************************
'Purpose: Intercept and act on special keys on me so
' that up and down arrows and scroll bar works as expected. Also
' automatically scroll screen when Tab key would otherwise disappear
' off the screen.
'Inputs: KeyCode - The ASCII(?) value of the key pressed
'Outputs: None
'***************************************************************************
Dim nScrollValue As Double
Dim nOnePage As Integer
nOnePage = Me.VScroll1.Height
If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
If KeyCode = vbKeyPageDown Then
nScrollValue = -Me.picPicture.Top + nOnePage
Else
nScrollValue = -Me.picPicture.Top - nOnePage
End If
'Make sure that the scroll bar 'handle' is not attempted to be positioned
'below the bottom of the scroll bar.
If nScrollValue > Me.VScroll1.Max Then
nScrollValue = Me.VScroll1.Max
Me.picPicture.Top = -Me.VScroll1.Max
End If
If nScrollValue > 0 Then
Me.VScroll1.Value = nScrollValue
Else
Me.VScroll1.Value = 0
End If
End If
End Sub
Private Sub HScroll1_Change()
picPicture.Left = -(HScroll1.Value)
End Sub
Private Sub picPicture_KeyDown(KeyCode As Integer, Shift As Integer)
CheckKeyCode KeyCode
End Sub
Private Sub ExitButton_Click()
Unload Me
End Sub
Re: Can't make the picturebox wide enough?
Make your inner picture picPicture's Height high enough to allow for the max number of lines. Also you need to make sure your scrollbar settings are correct so it will scroll the entire picture up and down
Re: Can't make the picturebox wide enough?
Hi there! Do I need to add a vertical scroll bar? The picture's height will stay the same, it just needs to scroll left to right because the number line is soooo big. I try to enter say 300 000 as the width of the picPicture, but it won't scroll any further than if I put say 100 000 for the width value.
Re: Can't make the picturebox wide enough?
I read your post wrong. I thought you were talking about a vertical problem.
What scale mode are you using on the picturebox
Re: Can't make the picturebox wide enough?
I am not sure what a scale model is, is that the scale width? it is 319566.8
Re: Can't make the picturebox wide enough?
But I DO have the mode set on twip. :)
Re: Can't make the picturebox wide enough?
ScaleMode means Pixels or Twips or some other mode. It should be in Pixels
The .Value, .SmallChange, .LargeChange, .Min, and .Max, properties of a scrollbar are all Integer variable meaning you can't have values greater than 32,767. So if your picturebox has a width greater than 32,767 you wont be able to scroll the full width of the picturebox.
What is the width of your inner picturebox. What is the width of each line
What are your values for .Min, .Max
Re: Can't make the picturebox wide enough?
Oh the inner picture box picPicture would need to have a width of around 100 000 to show all of it.
I do not have the min or max values defined yet.
The small and large change for the scroll bar though is
HScroll1.SmallChange = 300
HScroll1.LargeChange = picWindow.Width
2 Attachment(s)
Re: Can't make the picturebox wide enough?
With some calculations and some drawing you can dispense with the "dueling PictureBox" approach altogether. And for that matter do you really need a scrollbar? You could still use one of course.
Re: Can't make the picturebox wide enough?
Quote:
Originally Posted by
dilettante
With some calculations and some drawing you can dispense with the "dueling PictureBox" approach altogether. And for that matter do you really need a scrollbar? You could still use one of course.
Very nice demo. Your code is always neat and beautiful.
Thanks for the concept and sample.
Re: Can't make the picturebox wide enough?
That is awesome, and I am sorry for the late reply. I have used this and the kids like it because visual learners love this stuff. I hate to bother, but I was wondering if you could, or could show me how to add something.
I use the program to show students that you can turn a subtraction problem into adding, but starting with the small number and "jumping" to the big one. Ex: 19 - 6 = 13
The student can start at 6, and make jumps by clicking on the next number. So if I could, I can click on 6, and then 10 because kids like 10. Usually on the board I would draw an arch between those number to visualize the jump. Then keep jumping to 19, then add the jumps. So a jump from 6 to 10 would be 4, then 10 to 19 would be 9, so 4 + 9 = 13.
I don't know how, but if the user could click on a number, then click on another number, then an arch would be drawn between those two numbers, that would be awesome!
Sorry if it seems like I'm asking for much!
P.S. LaVople posted this in another thread. It draw 180 degree archs once the user clicks on two points.
VB Code:
Option Explicit
Private Type POINTF
X As Single
Y As Single
End Type
Dim tPts(0 To 1) As POINTF
Dim bNeed2ndPoint As Boolean
Private Sub DrawArcPoints(PicBox As PictureBox)
Dim xyDiff As POINTF
Dim Radius As Single
Dim Center As POINTF
Dim Angles(0 To 1) As Single, a As Long
Dim PI As Single
PI = Atn(1) * 4
Center.X = (tPts(0).X + tPts(1).X) / 2
Center.Y = (tPts(0).Y + tPts(1).Y) / 2
Radius = Sqr((Center.X - tPts(0).X) ^ 2 + (Center.Y - tPts(0).Y) ^ 2)
For a = 0 To 1
xyDiff.X = Center.X - tPts(a).X
xyDiff.Y = tPts(a).Y - Center.Y
If Abs(xyDiff.X) < 0.00000001 Then xyDiff.X = 0!
If Abs(xyDiff.Y) < 0.00000001 Then xyDiff.Y = 0!
If xyDiff.X <> 0! Then
Angles(a) = Atn(xyDiff.Y / xyDiff.X)
If xyDiff.X < 0 Then Angles(a) = Angles(a) + PI
ElseIf xyDiff.Y < 0 Then
Angles(a) = 3 * PI / 2 '90
Else
Angles(a) = PI / 2 '270
End If
If Angles(a) < 0! Then Angles(a) = Angles(a) + PI * 2
Next
' next 2 lines are for visual debugging
PicBox.Line (tPts(0).X, tPts(0).Y)-(tPts(1).X, tPts(1).Y), vbBlue
PicBox.Circle (Center.X, Center.Y), 5, vbWhite
' do the results
PicBox.Circle (Center.X, Center.Y), Radius, vbRed, Angles(0), Angles(1)
End Sub
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bNeed2ndPoint Then
Picture1.Circle (X, Y), 5, vbBlack
tPts(1).X = X: tPts(1).Y = Y
bNeed2ndPoint = False
DrawArcPoints Picture1
Else
Picture1.Cls
Picture1.Circle (X, Y), 5, vbBlack
tPts(0).X = X: tPts(0).Y = Y
bNeed2ndPoint = True
End If
End Sub
This code does help big time. I am just wondering if there was a way to make the arcs not too high? Also is there a way to keep the arcs after they are made to stay "drawn" on the picturebox? Ideally I would like the arcs to move along with the number line as you go forwards and backwards. :)
Re: Can't make the picturebox wide enough?
It looks like a common core lesson to me. Being an old fart, I say ditch the idea of teaching kids the common core BS and stick with something a little less abstract.
Re: Can't make the picturebox wide enough?
Quote:
Originally Posted by
Justin M
... . I am just wondering if there was a way to make the arcs not too high? Also is there a way to keep the arcs after they are made to stay "drawn" on the picturebox? Ideally I would like the arcs to move along with the number line as you go forwards and backwards. :)
Well, the code could be modified, but it would take a bit of math. 180 degrees is easy, but to keep the arc low you have to have the angle vary and the radius would have to vary to be the distance based on a chord of the circle, the chord being based on the desired height of the arc and the distance between the numbers.
Actually, thinking about it, it probably isn't too hard, just a few steps of basic trigonometry, but in this case another approach might actually be easier.
If you had an image of an arc the right vertical size that was sized horizontally to go between two adjacent numbers of your number line, you could use the Paint statement to stretch that image horizontally however many spaces you needed.
As far as making it "stick", or multiple copies of it "stick" to the drawing, I would need to checkout dilettante's code to see how he is drawing the numberline to see how to fit any new drawing code into it. I probably won't be looking at it anytime soon, so maybe someone else will come along and carry on.