Results 1 to 7 of 7

Thread: Looking for a better Scroll bar code (badly needed)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Resolved Looking for a better Scroll bar code (badly needed)

    The code I'm using now has worked the best, compared to other codes, for all my apps until now.
    The problem is that I have a TON of Picture Boxes and Labels that are loaded at runtime and they go somewhat beyond the maximum stretch of the scrollbars which effectively makes me unable to scroll over enough and view those Picture Boxes and Labels.

    SBar - A Picture Box on Form1 with .Align = 2 - Align Bottom
    HS - A HScrollBar
    VS - A VScrollBar

    Code as follows:
    VB Code:
    1. Dim VSLVal As Integer
    2. Dim HSLVal As Integer
    3. Dim HMax As Integer
    4. Dim VMax As Integer
    5.  
    6. Private Sub Form_Load()
    7. On Error Resume Next
    8. Dim Cntrl As Control
    9.  
    10. For Each Cntrl In Me.Controls
    11.  If (Not TypeOf Cntrl Is HScrollBar) And _
    12.     (Not TypeOf Cntrl Is VScrollBar) Then
    13.   If (Cntrl.Top + Cntrl.Height + 125) > VMax Then
    14.    VMax = Cntrl.Top + Cntrl.Height + 125
    15.   End If
    16.   If (Cntrl.Left + Cntrl.Width + 125) > HMax Then
    17.    HMax = Cntrl.Left + Cntrl.Width + 125
    18.   End If
    19.  End If
    20. Next
    21. On Error GoTo 0
    22.  
    23. With HS
    24. .Left = 0
    25. .Top = Me.ScaleHeight - .Height
    26. SBar.Height = .Height
    27. .Width = Me.ScaleWidth - VS.Width
    28. .Max = HMax - .Width
    29. If .Max < 0 Then .Max = 0
    30. End With
    31.  
    32. With VS
    33. .Height = Me.ScaleHeight - HS.Height
    34. .Left = Me.ScaleWidth - .Width
    35. .Top = 0
    36. .Max = VMax - .Height
    37. If .Max < 0 Then .Max = 0
    38. End With
    39.  
    40. If HS.Max <= 0 Then HS.Enabled = False
    41. If VS.Max <= 0 Then VS.Enabled = False
    42. End Sub
    43.  
    44. Private Sub Form_Resize() 'complete
    45. If Me.WindowState = 1 Then
    46.  Exit Sub
    47. ElseIf Me.Height < 2525 Then
    48.  Me.Height = 2525
    49. ElseIf Me.Width < 2525 Then
    50.  Me.Width = 2525
    51. End If
    52.  
    53. With HS
    54. .Left = 0
    55. .Top = Me.ScaleHeight - .Height
    56. .Width = Me.ScaleWidth - VS.Width
    57. .Max = HMax - .Width
    58. End With
    59.  
    60. With VS
    61. .Height = Me.ScaleHeight - HS.Height
    62. .Left = Me.ScaleWidth - .Width
    63. .Top = 0
    64. .Max = VMax - .Height
    65. End With
    66.  
    67. If HS.Max <= 0 Then
    68.  HS.Enabled = False
    69.  HS.Max = 0
    70. Else
    71.  HS.Enabled = True
    72. End If
    73. If VS.Max <= 0 Then
    74.  VS.Enabled = False
    75.  VS.Max = 0
    76. Else
    77.  VS.Enabled = True
    78. End If
    79. End Sub
    80.  
    81. Private Sub HSPositionChanged() 'complete
    82. On Error Resume Next
    83. Dim Val As Integer, Cntrl As Control
    84. Val = HSLVal - HS.Value
    85. For Each Cntrl In Me.Controls
    86.  If TypeOf Cntrl Is HScrollBar Or _
    87.     TypeOf Cntrl Is VScrollBar Or _
    88.     TypeOf Cntrl Is Menu Then
    89.  ElseIf TypeOf Cntrl Is Line Then
    90.   Cntrl.X1 = Cntrl.X1 + Val
    91.   Cntrl.X2 = Cntrl.X2 + Val
    92.  Else
    93.   Cntrl.Left = Cntrl.Left + Val
    94.  End If
    95. Next
    96. HSLVal = HS.Value
    97. End Sub
    98.  
    99.  
    100. Private Sub VSPositionChanged() 'complete
    101. On Error Resume Next
    102. Dim Val As Integer, Cntrl As Control
    103. Val = VSLVal - VS.Value
    104. For Each Cntrl In Me.Controls
    105.  If TypeOf Cntrl Is HScrollBar Or _
    106.     TypeOf Cntrl Is VScrollBar Or _
    107.     TypeOf Cntrl Is Menu Then
    108.  ElseIf TypeOf Cntrl Is Line Then
    109.   Cntrl.Y1 = Cntrl.Y1 + Val
    110.   Cntrl.Y2 = Cntrl.Y2 + Val
    111.  Else
    112.   Cntrl.Top = Cntrl.Top + Val
    113.  End If
    114. Next
    115. VSLVal = VS.Value
    116. End Sub
    117.  
    118. Public Sub resizescrolbars()
    119. 'VS.Value = 0
    120. 'HS.Value = 0
    121. On Error Resume Next
    122. Dim Cntrl As Control
    123. For Each Cntrl In Me.Controls
    124.  If (Not TypeOf Cntrl Is HScrollBar) And _
    125.     (Not TypeOf Cntrl Is VScrollBar) Then
    126.   If (Cntrl.Top + Cntrl.Height + 125) > VMax Then
    127.    VMax = Cntrl.Top + Cntrl.Height + 125
    128.   End If
    129.   If (Cntrl.Left + Cntrl.Width + 125) > HMax Then
    130.    HMax = Cntrl.Left + Cntrl.Width + 125
    131.   End If
    132.  End If
    133. Next
    134. On Error GoTo 0
    135. With HS
    136. .Left = 0
    137. .Top = Me.ScaleHeight - .Height
    138. SBar.Height = .Height
    139. .Width = Me.ScaleWidth - VS.Width
    140. .Max = HMax - .Width
    141. If .Max < 0 Then .Max = 0
    142. End With
    143. With VS
    144. .Height = Me.ScaleHeight - HS.Height
    145. .Left = Me.ScaleWidth - .Width
    146. .Top = 0
    147. .Max = VMax - .Height
    148. If .Max < 0 Then .Max = 0
    149. End With
    150. If HS.Max <= 0 Then HS.Enabled = False
    151. If VS.Max <= 0 Then VS.Enabled = False
    152. If Me.WindowState = 1 Then
    153.  Exit Sub
    154. ElseIf Me.Height < 2525 Then
    155.  Me.Height = 2525
    156. ElseIf Me.Width < 2525 Then
    157.  Me.Width = 2525
    158. End If
    159. With HS
    160. .Left = 0
    161. .Top = Me.ScaleHeight - .Height
    162. .Width = Me.ScaleWidth - VS.Width
    163. .Max = HMax - .Width
    164. End With
    165. With VS
    166. .Height = Me.ScaleHeight - HS.Height
    167. .Left = Me.ScaleWidth - .Width
    168. .Top = 0
    169. .Max = VMax - .Height
    170. End With
    171. If HS.Max <= 0 Then
    172.  HS.Enabled = False
    173.  HS.Max = 0
    174. Else
    175.  HS.Enabled = True
    176. End If
    177. If VS.Max <= 0 Then
    178.  VS.Enabled = False
    179.  VS.Max = 0
    180. Else
    181.  VS.Enabled = True
    182. End If
    183. End Sub
    184.  
    185. Private Sub HS_Change() 'complete
    186. HSPositionChanged
    187. End Sub
    188. Private Sub HS_Scroll() 'complete
    189. HSPositionChanged
    190. End Sub
    191.  
    192. Private Sub vs_Change() 'complete
    193. VSPositionChanged
    194. End Sub
    195. Private Sub vs_Scroll() 'complete
    196. VSPositionChanged
    197. End Sub

    And in a Module I have:
    VB Code:
    1. Public Sub drawstuff(Index As Integer)
    2. Call UnloadData 'unloads all the controls so that when we load I have the Right number of controls
    3. Form1.HS.Value = 0
    4. Form1.VS.Value = 0
    5. Call LoadData(Index) 'loads the controls
    6. Call Form1.EnableSelection 'stuff for moving things with mouse
    7. 'resize the scrollbars
    8. Call Form1.resizescrolbars
    9. Form1.HS.Value = 0
    10. Form1.VS.Value = 0
    11. End Sub

    Here are all of the Picture box’s Tool tip, Top, and Left as given by debug.print:
    (see next post, this one is too long)



    PS:I can post the whole 6 mb project if needed, (about 150k is the actual program, the rest of it are graphics).
    Last edited by Tontow; Feb 4th, 2007 at 01:36 AM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: Looking for a better Scroll bar code (badly needed)

    Rixian : Top: 0 : Left: 3000
    Platform : Top: 4000 : Left: 3000
    Garrison : Top: 2000 : Left: 3000
    Garrison (Str) : Top: 6000 : Left: 3000
    Tactical : Top: 4000 : Left: 6000
    Tactical (Adv) : Top: 8000 : Left: 3000
    Expansion : Top: 4000 : Left: 9000
    Expansion (Adv) : Top: 8000 : Left: 6000
    Supremacy : Top: 4000 : Left: 12000
    Supremacy (Adv) : Top: 8000 : Left: 9000
    Shipyard : Top: 6000 : Left: 6000
    Shipyard (Dry) : Top: 14000 : Left: 3000
    Teleport : Top: 4000 : Left: 15000
    Refinery : Top: 4000 : Left: 18000
    Outpost : Top: 4000 : Left: 21000
    GA: Ship Speed 1 : Top: 8000 : Left: 12000
    GA: EW Range 1 : Top: 6000 : Left: 9000
    GA: EW Range 2 : Top: 10000 : Left: 3000
    Version: DN 00.04.50 : Top: 4000 : Left: 24000
    Observer : Top: 4000 : Left: 27000
    Cash Box : Top: 4000 : Left: 30000
    [S/E] Counter 2 : Top: 6000 : Left: 12000
    [S/E] Counter 3 : Top: 10000 : Left: 6000
    Hvy Counter 1 : Top: 4000 : Left: 33000
    Teleport Probe 1 : Top: 8000 : Left: 15000
    Sig Cloak 1 : Top: 4000 : Left: 36000
    Hvy Sig Cloak 1 : Top: 4000 : Left: 39000
    Hvy Sig Cloak 2 : Top: 8000 : Left: 18000
    Sm Shield 2 : Top: 4000 : Left: 42000
    Sm Shield 3 : Top: 8000 : Left: 21000
    Med Shield 2 : Top: 4000 : Left: 45000
    Med Shield 3 : Top: 8000 : Left: 24000
    GA: Ship Speed 2 : Top: 16000 : Left: 3000
    Hvy Counter 2 : Top: 8000 : Left: 27000
    Hvy Counter 3 : Top: 16000 : Left: 6000
    Large Shield 2 : Top: 8000 : Left: 30000
    GA: PW Range 1 : Top: 6000 : Left: 15000
    GA: PW Range 2 : Top: 10000 : Left: 9000
    GA: PW&EW Damage 1 : Top: 6000 : Left: 18000
    GA: PW&EW Damage 2 : Top: 10000 : Left: 12000
    GA: Ship Signature 1 : Top: 6000 : Left: 21000
    GA: Ship Signature 2 : Top: 10000 : Left: 15000
    GA: Ship Acceleration 1 : Top: 6000 : Left: 24000
    GA: Ship Shield 1 : Top: 6000 : Left: 27000
    GA: Ship Shield 2 : Top: 10000 : Left: 18000
    GA: Ship Energy 1 : Top: 6000 : Left: 30000
    GA: Ship Energy 2 : Top: 10000 : Left: 21000
    Lt Booster 1 : Top: 4000 : Left: 48000
    Lt Booster 2 : Top: 8000 : Left: 33000
    Booster 1 : Top: 4000 : Left: 51000
    LRM Aleph Res 1 : Top: 8000 : Left: 36000
    LRM Aleph Res 2 : Top: 10000 : Left: 24000
    LRM Aleph Res 3 : Top: 12000 : Left: 3000
    Large Shield 3 : Top: 16000 : Left: 9000
    Hvy Station Drone 2 : Top: 16000 : Left: 12000
    GA: Ship Acceleration 2 : Top: 10000 : Left: 27000
    EMP Mine 1 : Top: 6000 : Left: 33000
    GA: Ripcord 1 : Top: 6000 : Left: 36000
    GA: Station Shield 1 : Top: 6000 : Left: 39000
    EMP Mine 2 : Top: 10000 : Left: 30000
    GA: Ripcord 2 : Top: 10000 : Left: 33000
    GA: Station Shield 2 : Top: 10000 : Left: 36000
    GA: Station Hull 1 : Top: 6000 : Left: 42000
    Station Drone 2 : Top: 10000 : Left: 39000
    Hvy Cmb Drone 1 : Top: 6000 : Left: 45000
    GA: Ship Sensors 1 : Top: 6000 : Left: 48000
    GA: Ship Sensors 2 : Top: 10000 : Left: 42000
    PW SkyCap 1 : Top: 4000 : Left: 54000
    EW Disruptor 1 : Top: 4000 : Left: 57000
    ER Nanite 2 : Top: 8000 : Left: 39000
    GA: Ship Hull 1 : Top: 6000 : Left: 51000
    GA: Ship Hull 2 : Top: 10000 : Left: 45000
    GA: Station Hull 2 : Top: 10000 : Left: 48000
    GA: Ship Agility 1 : Top: 6000 : Left: 54000
    GA: Ship Agility 2 : Top: 10000 : Left: 51000
    PW SkyCap 2 : Top: 8000 : Left: 42000
    PW SkyCap 3 : Top: 16000 : Left: 15000
    PE LongTom : Top: 18000 : Left: 3000
    Hvy Cmb Drone 2 : Top: 10000 : Left: 54000
    Combat Drone 2 : Top: 6000 : Left: 57000
    Teleport Probe 2 : Top: 10000 : Left: 57000
    EWS Probe 2 : Top: 6000 : Left: 60000
    EWS Probe 3 : Top: 10000 : Left: 60000
    PW Lancer 2 : Top: 8000 : Left: 45000
    PW Lancer 3 : Top: 16000 : Left: 18000
    GA: He3 Yield 1 : Top: 6000 : Left: 63000
    GA: He3 Yield 2 : Top: 10000 : Left: 63000
    GA: Faster He3 1 : Top: 6000 : Left: 66000
    GA: Faster He3 2 : Top: 10000 : Left: 66000
    Combat Drone 3 : Top: 10000 : Left: 69000
    Mine Pack 1 : Top: 6000 : Left: 69000
    Mine Pack 2 : Top: 10000 : Left: 72000
    Cruise Booster : Top: 6000 : Left: 72000
    Sig Cloak 2 : Top: 6000 : Left: 75000
    Sig Cloak 3 : Top: 10000 : Left: 75000
    SRM Nerve Gas : Top: 10000 : Left: 78000
    Enh Miner : Top: 4000 : Left: 60000
    Enh Constructor : Top: 4000 : Left: 63000
    Enh Carrier Drone : Top: 4000 : Left: 66000
    Bomber : Top: 4000 : Left: 69000
    Pulse Probe : Top: 6000 : Left: 78000
    Booster 2 : Top: 6000 : Left: 81000
    Booster 3 : Top: 10000 : Left: 81000
    Hvy Booster : Top: 12000 : Left: 6000
    XRP Anti-Base 1 : Top: 6000 : Left: 84000
    XRP Anti-Base 2 : Top: 10000 : Left: 84000
    Prox Mine 2 : Top: 6000 : Left: 87000
    Upgrade Light Class : Top: 8000 : Left: 48000
    Prox Mine 3 : Top: 10000 : Left: 87000
    Retro Booster : Top: 6000 : Left: 90000
    Hvy Bomber : Top: 8000 : Left: 51000
    PW EMP Cannon 1 : Top: 6000 : Left: 93000
    PW EMP Cannon 2 : Top: 10000 : Left: 90000
    PW Mini-Gun 2 : Top: 6000 : Left: 96000
    PW Mini-Gun 3 : Top: 10000 : Left: 93000
    EW Stinger 2 : Top: 6000 : Left: 99000
    PW Auto-Cannon 2 : Top: 6000 : Left: 102000
    Adv Miner : Top: 10000 : Left: 96000
    EW Sniper Rifle 1 : Top: 6000 : Left: 105000
    PW Auto-Cannon 3 : Top: 10000 : Left: 99000
    EW Disruptor 2 : Top: 6000 : Left: 108000
    EW Disruptor 3 : Top: 10000 : Left: 102000
    EW Galvonic Blaster : Top: 10000 : Left: 105000
    Adv Constructor : Top: 10000 : Left: 108000
    Gunship : Top: 8000 : Left: 54000
    EW Sniper Rifle 2 : Top: 10000 : Left: 111000
    EW Utl Cannon 2 : Top: 6000 : Left: 111000
    Troop Transport : Top: 6000 : Left: 114000
    PW Gattling Gun 2 : Top: 6000 : Left: 117000
    PW Gattling Gun 3 : Top: 10000 : Left: 114000
    EW Utl Cannon 3 : Top: 10000 : Left: 117000
    Tower SC Drone : Top: 6000 : Left: 120000
    Stealth Bomber : Top: 10000 : Left: 120000
    Stealth Fighter : Top: 6000 : Left: 123000
    Fighter/Bomber : Top: 12000 : Left: 9000
    Enh Fighter : Top: 6000 : Left: 126000
    Hvy Troop Transport : Top: 10000 : Left: 123000
    Adv Fighter : Top: 10000 : Left: 126000
    Adv Stl Fighter : Top: 10000 : Left: 129000
    Adv Scout : Top: 8000 : Left: 57000
    Hvy Scout : Top: 10000 : Left: 132000
    Interceptor : Top: 6000 : Left: 129000
    Upgrade Medium Class : Top: 10000 : Left: 135000
    Upgrade Heavy Class : Top: 12000 : Left: 12000
    Hvy Interceptor : Top: 10000 : Left: 138000
    Upgrade Garrison : Top: 4000 : Left: 72000
    Upgrade Expansion : Top: 6000 : Left: 132000
    Upgrade Super Hvy Class : Top: 14000 : Left: 6000
    Upgrade Tactical Lab : Top: 6000 : Left: 135000
    Upgrade Supremacy : Top: 6000 : Left: 138000
    Reinforcement : Top: 4000 : Left: 75000
    Super Cheat : Top: 4000 : Left: 78000
    Game Settings : Top: 0 : Left: 6000

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Looking for a better Scroll bar code (badly needed)

    Use ScaleMode pixels instead.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: Looking for a better Scroll bar code (badly needed)

    No, that didnt do it

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Looking for a better Scroll bar code (badly needed)

    It'll do it once you shrink all the values that calculate new positions for elements by 15 (which is what one pixel for a twip is). Note that you probably need to do it for all container elements (forms, pictureboxes...). After this 100 000 goes down to 6666, which fits within scrollbar value range.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: [RESOLVED] Looking for a better Scroll bar code (badly needed)

    Well it just had to happen; I'm coming dangerously close to running into the same problem.
    The problem is that I have a TON of Picture Boxes and Labels that are loaded at runtime and they go somewhat beyond the maximum stretch of the scrollbars which effectively makes me unable to scroll over enough and view those Picture Boxes and Labels.
    Is there any way to extend the maximum range of the scrollbars indefinitely?

  7. #7
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Looking for a better Scroll bar code (badly needed)

    Wouldn't it be easier to put all of your controls, except for the scrollbars, in a picturebox? Then all you would need to do is reposition the picturebox to move all of the controls relative to the form.

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