Solved

use of VSCrollbars

Posted on 2004-10-15
9
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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