Solved

use of VSCrollbars

Posted on 2004-10-15
9
170 Views
Last Modified: 2010-05-02
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
Comment
Question by:anshuma
  • 3
  • 3
  • 2
  • +1
9 Comments
 

Author Comment

by:anshuma
Comment Utility
and how do I implement a scroll bar on a maximized form
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
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
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 150 total points
Comment Utility
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
 
LVL 3

Accepted Solution

by:
pra_kumar03 earned 300 total points
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:pra_kumar03
Comment Utility
Also there is one command button with the name as Command1
0
 

Author Comment

by:anshuma
Comment Utility
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
 

Author Comment

by:anshuma
Comment Utility
I got that, its setting the tabstop to false, right
0
 
LVL 3

Expert Comment

by:pra_kumar03
Comment Utility
I did keep the tabstop for the scroll bars to false.
0
 
LVL 4

Assisted Solution

by:AjithJose
AjithJose earned 50 total points
Comment Utility

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now