Please can anyboby help send me codes to add scroll bars to a form

Dani AI

Generated

asked for code to add scroll bars to a form. pointed to an earlier thread, and suggested creating a scrollbar control array at design time and adding members at runtime. The core point to clarify: VB6 and VB.NET use different, simpler approaches. The two common situations are (A) scrolling drawn content and (B) scrolling standard controls placed on a surface.

VB6 notes and a practical recipe:

  • The Form.ScrollBars property only affects the form's drawing surface; it does not move standard child controls. That is why placing controls directly on a form and turning on Form.ScrollBars will not "scroll" those controls.
  • To scroll controls, place them inside a container (PictureBox or Frame). Make the container hold the full virtual content size, then add HScroll and VScroll controls on the form.
  • Set each scrollbar Min = 0 and Max = (contentSize - visibleSize). Adjust SmallChange/LargeChange for sensible stepping.
  • In the scrollbar events move the container by the negative of the scrollbar value so the correct portion of the content becomes visible.

Example VB6 handlers:

Private Sub HScroll1_Change()
    PictureBox1.Left = -HScroll1.Value
End Sub

Private Sub VScroll1_Change()
    PictureBox1.Top = -VScroll1.Value
End Sub

VB.NET tip: use a Panel (or FlowLayoutPanel) and set Panel1.AutoScroll = True; child controls placed inside will be scrolled automatically without manual scrollbar handling.

Additional tips and caveats:

  • As suggested, a control array of scrollbars makes dynamic creation easier (create one at design time with an Index and add members at runtime). Remember to unload dynamic members when done.
  • Keep units consistent (VB6 uses twips by default); if numbers look off, convert units or change ScaleMode.
  • For heavy content or visual flicker, set the container's AutoRedraw/back-buffering or use double-buffering techniques to improve smoothness.

Recommended Answers

All 2 Replies

create 1 control array scrollbar during design time example name: hs1 and set index = 0

the code to create a new scrollbar:

load hs1(1)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.