Solved

use of VSCrollbars

Posted on 2004-10-15
9
177 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
ID: 12322620
and how do I implement a scroll bar on a maximized form
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12322654
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
ID: 12322800
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 3

Accepted Solution

by:
pra_kumar03 earned 300 total points
ID: 12323890
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
 
LVL 3

Expert Comment

by:pra_kumar03
ID: 12323898
Also there is one command button with the name as Command1
0
 

Author Comment

by:anshuma
ID: 12324218
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
ID: 12324271
I got that, its setting the tabstop to false, right
0
 
LVL 3

Expert Comment

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

Assisted Solution

by:AjithJose
AjithJose earned 50 total points
ID: 12329168

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 57
Write data from SQL to CSV file - position 1 57
How to debug this code 7 61
Send outlook email from VBS Script 2 28
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

815 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

12 Experts available now in Live!

Get 1:1 Help Now