Results 1 to 13 of 13

Thread: Can't make the picturebox wide enough?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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:
    1. Option Explicit
    2.  
    3. ' You have a royalty-free right to use, modify, reproduce and distribute
    4. ' the Sample Application Files (and/or any modified version) in any way
    5. ' you find useful, provided that you agree that Martin Liss has no warranty,
    6. ' obligations or liability for any Sample Application Files.
    7.  
    8.  
    9.  
    10.  
    11.  
    12. Private Sub Form_Activate()
    13.  
    14.     ' So that scrooling will happen if the user immediately presses
    15.     ' PageUp or PageDown
    16.     picPicture.SetFocus
    17.    
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.  
    22.  
    23.     HScroll1.Width = picWindow.Width
    24.  
    25.    ' HScroll1.Max = picPicture.Width - picWindow.Width
    26.  
    27.    
    28.     HScroll1.SmallChange = 200
    29.    
    30.     HScroll1.LargeChange = picWindow.Width
    31.    
    32.     If picPicture.Picture = 0 Then
    33.         lblNoPicture.Visible = True
    34.         lblNoPicture.Caption = "Change picPicture's Picture property to refer " _
    35.                              & "to the location of winnt.bmp (or any large picture)"
    36.     End If
    37.    
    38. End Sub
    39.  
    40.  
    41. Public Sub CheckKeyCode(KeyCode As Integer)
    42. '***************************************************************************
    43. 'Purpose: Intercept and act on special keys on me so
    44. '         that up and down arrows and scroll bar works as expected. Also
    45. '         automatically scroll screen when Tab key would otherwise disappear
    46. '         off the screen.
    47. 'Inputs:  KeyCode - The ASCII(?) value of the key pressed
    48. 'Outputs: None
    49. '***************************************************************************
    50.  
    51.     Dim nScrollValue As Double
    52.     Dim nOnePage As Integer
    53.    
    54.     nOnePage = Me.VScroll1.Height
    55.    
    56.     If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
    57.         If KeyCode = vbKeyPageDown Then
    58.             nScrollValue = -Me.picPicture.Top + nOnePage
    59.         Else
    60.             nScrollValue = -Me.picPicture.Top - nOnePage
    61.         End If
    62.         'Make sure that the scroll bar 'handle' is not attempted to be positioned
    63.         'below the bottom of the scroll bar.
    64.         If nScrollValue > Me.VScroll1.Max Then
    65.             nScrollValue = Me.VScroll1.Max
    66.             Me.picPicture.Top = -Me.VScroll1.Max
    67.         End If
    68.         If nScrollValue > 0 Then
    69.             Me.VScroll1.Value = nScrollValue
    70.         Else
    71.             Me.VScroll1.Value = 0
    72.         End If
    73.     End If
    74.    
    75. End Sub
    76.  
    77. Private Sub HScroll1_Change()
    78.  
    79.     picPicture.Left = -(HScroll1.Value)
    80.  
    81. End Sub
    82.  
    83. Private Sub picPicture_KeyDown(KeyCode As Integer, Shift As Integer)
    84.  
    85.     CheckKeyCode KeyCode
    86.    
    87. End Sub
    88.  
    89. Private Sub ExitButton_Click()
    90. Unload Me
    91. End Sub
    Last edited by Justin M; Oct 18th, 2015 at 10:17 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Can't make the picturebox wide enough?

    But I DO have the mode set on twip.

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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

  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

    Name:  sshot.png
Views: 256
Size:  14.6 KB
    Attached Files Attached Files

  10. #10
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: Can't make the picturebox wide enough?

    Quote Originally Posted by dilettante View Post
    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.

    Name:  sshot.png
Views: 256
Size:  14.6 KB
    Very nice demo. Your code is always neat and beautiful.
    Thanks for the concept and sample.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    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:
    1. Option Explicit
    2.  
    3. Private Type POINTF
    4.     X As Single
    5.     Y As Single
    6. End Type
    7. Dim tPts(0 To 1) As POINTF
    8. Dim bNeed2ndPoint As Boolean
    9.  
    10. Private Sub DrawArcPoints(PicBox As PictureBox)
    11.    
    12.     Dim xyDiff As POINTF
    13.     Dim Radius As Single
    14.     Dim Center As POINTF
    15.     Dim Angles(0 To 1) As Single, a As Long
    16.    
    17.     Dim PI As Single
    18.     PI = Atn(1) * 4
    19.    
    20.     Center.X = (tPts(0).X + tPts(1).X) / 2
    21.     Center.Y = (tPts(0).Y + tPts(1).Y) / 2
    22.     Radius = Sqr((Center.X - tPts(0).X) ^ 2 + (Center.Y - tPts(0).Y) ^ 2)
    23.    
    24.     For a = 0 To 1
    25.         xyDiff.X = Center.X - tPts(a).X
    26.         xyDiff.Y = tPts(a).Y - Center.Y
    27.    
    28.         If Abs(xyDiff.X) < 0.00000001 Then xyDiff.X = 0!
    29.         If Abs(xyDiff.Y) < 0.00000001 Then xyDiff.Y = 0!
    30.    
    31.         If xyDiff.X <> 0! Then
    32.             Angles(a) = Atn(xyDiff.Y / xyDiff.X)
    33.             If xyDiff.X < 0 Then Angles(a) = Angles(a) + PI
    34.         ElseIf xyDiff.Y < 0 Then
    35.             Angles(a) = 3 * PI / 2 '90
    36.         Else
    37.             Angles(a) = PI / 2 '270
    38.         End If
    39.    
    40.         If Angles(a) < 0! Then Angles(a) = Angles(a) + PI * 2
    41.     Next
    42.  
    43.     ' next 2 lines are for visual debugging
    44.     PicBox.Line (tPts(0).X, tPts(0).Y)-(tPts(1).X, tPts(1).Y), vbBlue
    45.     PicBox.Circle (Center.X, Center.Y), 5, vbWhite
    46.    
    47.     ' do the results
    48.     PicBox.Circle (Center.X, Center.Y), Radius, vbRed, Angles(0), Angles(1)
    49.  
    50. End Sub
    51.  
    52. Private Sub Form_Load()
    53.     Picture1.ScaleMode = vbPixels
    54. End Sub
    55.  
    56. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    57.  
    58.     If bNeed2ndPoint Then
    59.         Picture1.Circle (X, Y), 5, vbBlack
    60.         tPts(1).X = X: tPts(1).Y = Y
    61.         bNeed2ndPoint = False
    62.         DrawArcPoints Picture1
    63.     Else
    64.         Picture1.Cls
    65.         Picture1.Circle (X, Y), 5, vbBlack
    66.         tPts(0).X = X: tPts(0).Y = Y
    67.         bNeed2ndPoint = True
    68.     End If
    69. 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.
    Last edited by Justin M; Apr 20th, 2016 at 04:52 AM.

  12. #12
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,598

    Re: Can't make the picturebox wide enough?

    Quote Originally Posted by Justin M View Post
    ... . 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width