Solved

use of VSCrollbars

Posted on 2004-10-15
9
189 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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