[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

use of VSCrollbars

Hi,
I am loading a variable number of text boxes on the fly on a form. But if I load say 14 big text boxes then the lower ones are not visible because I cannot scroll the form. How can I implement a vscrollbar so that all my controls are visible.

Similarly if I have a form with so many fields that I need to scroll down to fill in the entire form. How can I implement a scroll bar.
0
anshuma
Asked:
anshuma
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
anshumaEngineeringAuthor Commented:
and how do I implement a scroll bar on a maximized form
0
 
Erick37Commented:
Have a look at the example at VBNet.  This code sample uses pictureboxes to create a scrollable viewport.  Try it, it works great.

Creating a Scrollable Viewport to Simulate a Scrollable Form
http://vbnet.mvps.org/index.html?code/forms/scrollviewport.htm

0
 
Erick37Commented:
Another technique is to make your form a borderless child of an MDI Form.  The MDI form will then automatically scroll your child form.  Here's an example:

'The MDI form loads your main form (named frmMainChild) which has its Borderstyle set to 0 - None
'and MDIChild = True

Option Explicit

Const max_height = 20000 '<<-- change as needed
Const max_width = 10000

Private Sub MDIForm_Load()
    frmMainChild.Show
    frmMainChild.Move 0, 0, max_width, max_height
End Sub

Private Sub MDIForm_Resize()
   
    With frmMainChild
    'Resize the child form
    'width
    If ScaleWidth > max_width Then
        .Width = ScaleWidth
    Else
        If .Width <> max_width Then
            .Width = max_width
        End If
    End If
    'Height
    If ScaleHeight > max_height Then
        .Height = ScaleHeight
    Else
        If .Height <> max_height Then
            .Height = max_height
        End If
    End If
    End With
   
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
pra_kumar03Commented:
I worked out something similar.  Would try to put the code for it
I put some a VscrollBAr  and HScrollBAr on the Form with name as VScroll1 and HScroll1 respectively. There is code for Resize, and also for the scroll function


Dim vscroll_value As Integer
Dim hscroll_value As Integer
Private Sub Form_Load()
vscroll_value = 0
VScroll1.Max = 20  '( set this to the max pos u want to go divide by 300)
VScroll1.Min = 0
HScroll1.Max = 20
HScroll1.Min = 0
End Sub

Private Sub Form_Resize()
If (ScaleHeight - HScroll1.Height) > 0 Then
VScroll1.Top = 0
VScroll1.Left = Form1.ScaleWidth - VScroll1.Width
VScroll1.Height = ScaleHeight - HScroll1.Height
End If

HScroll1.Left = 0
HScroll1.Top = Form1.ScaleHeight - HScroll1.Height
HScroll1.Width = ScaleWidth - VScroll1.Width

Command1.Width = VScroll1.Width
Command1.Height = HScroll1.Height
Command1.Top = HScroll1.Top
Command1.Left = VScroll1.Left
Form1.SetFocus

End Sub

Private Sub HScroll1_Change()
Dim i As Integer
For i = 0 To Me.Controls.Count - 1
  If TypeOf Me.Controls(i) Is VScrollBar Or TypeOf Me.Controls(i) Is HScrollBar Then
      'Nothing to be done
  Else
    If Me.Controls(i).Name <> "Command1" Then
      Me.Controls(i).Left = Me.Controls(i).Left + (200 * (hscroll_value - HScroll1.Value))
    End If
  End If
Next i
hscroll_value = HScroll1.Value
End Sub



Private Sub VScroll1_Change()
Dim i As Integer
For i = 0 To Me.Controls.Count - 1
  If TypeOf Me.Controls(i) Is VScrollBar Or TypeOf Me.Controls(i) Is HScrollBar Then
      'Nothing to be done
  Else
  If Me.Controls(i).Name <> "Command1" Then
      Me.Controls(i).Top = Me.Controls(i).Top + (200 * (vscroll_value - VScroll1.Value))
    End If
  End If
Next i
vscroll_value = VScroll1.Value
End Sub
0
 
pra_kumar03Commented:
Also there is one command button with the name as Command1
0
 
anshumaEngineeringAuthor Commented:
thanks pra_kumar03  but once I scroll the scrollbar it keeps on blinking , is there anyway we can stop its blinking. I am using VB 6.0 on windows xp
0
 
anshumaEngineeringAuthor Commented:
I got that, its setting the tabstop to false, right
0
 
pra_kumar03Commented:
I did keep the tabstop for the scroll bars to false.
0
 
AjithJoseCommented:

Checkout this URL, download and test the code and its demo. You can definitely solve the scrolling problem

http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/Adding_Scroll_Bars_To_Forms__PictureBoxes_and_UserControls/article.asp
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now