|
-
Dec 17th, 2002, 09:17 AM
#1
Thread Starter
Junior Member
Scrollbar in controls with API
Hello everyone.
I want to load multiple textbox at run-time in a form. The problem is that after many loading of textbox (going from the top to bottom), many textbox are hidden because the form is too small...
I need a scroll bar on my form and I was wondering if there was any way to do it with the windows API. If there is a way, will it also be easy to ajust the maximum scroll on that scroll bar (because may be I would load more textbox in my form).
If it's not possible to do it for a form, is it possible to do it for a picture box, or some container control ? Thank you very much for your times. This forum is very handy and all of you people are really nice!
Dan
-
Dec 17th, 2002, 10:15 AM
#2
Fanatic Member
I don't know of an api way to do it, but you could just put a scroll bar on the form, and when its clicked, move all the text boxes top property up or down to similiate the scroll.
It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.
-
Dec 17th, 2002, 10:32 AM
#3
Frenzied Member
If you subclass your form and change the window style to have WS_HSCROLL and WS_VSCROLL set then your from will show scrollbars...I have wrapped this functionality in the EventVB.dll which you could use to make your form scroll as per example 4 on this page e.g.:
VB Code:
Option Explicit
'\\ EventVB event sink classes, declared WithEvents
Private WithEvents apiLink As EventVB.APIFunctions
Private WithEvents apiWnd As EventVB.ApiWindow
Private Sub Form_Load()
'\\ Initiate the EventVB link
Set apiLink = New EventVB.APIFunctions
'\\ Start subclassing this window
Set apiWnd = New EventVB.ApiWindow
apiWnd.hWnd = Me.hWnd
With apiWnd
.VirtualHeight = 300
.VirtualWidth = 300
.ScrollBars = vbBoth
.AutoScroll = True
End With
apiLink.SubclassedWindows.Add apiWnd
End Sub
Hope this helps,
Duncan
-
Dec 17th, 2002, 10:55 AM
#4
Thread Starter
Junior Member
Thankx, but one more question
Wow! That's great! Thankx a lot!
Now how do change the max value of this scrollbar after the form is loaded...?
Thanks again for your help.
-
Dec 17th, 2002, 11:01 AM
#5
Thread Starter
Junior Member
another question
Hi, I used the EventVB.dll and the scroll is working well and everything until I decide to resize the window or maximize it...
Do you know why?
-
Dec 17th, 2002, 11:05 AM
#6
Frenzied Member
(a) Change VirtualHeight and VirtualWidth to reflect the size (in pixels) of your scrollable area. For example if you set them to 1280 and 960 and your secreen is 640 x 480 then the scrollable area should be 2 times as big as the maximised window.
(b) Change VirtualPageHeight and VirtualPageWidth to set the large change amount (again in pixels) of the scrollbars
(c) What is happening after you maximise the form?
Thanks in advance,
D
-
Dec 17th, 2002, 11:13 AM
#7
Thread Starter
Junior Member
Thanks again for your help
Well, I think my computer was out of memory and that was why the scrolling wasn't working anymore after I maximed the window. (I was able to move the scroll button but nothing would move in my form). But now, it's working and thanks to you!
Now it seems like your EventVB.dll has many useful and interesting functions. Is there any documentation for that dll. May be I can find some other useful functions to use for my application. Thank you!
-
Dec 17th, 2002, 11:32 AM
#8
Frenzied Member
You can download the compiled help file from here - note that (as always) this documentation lags a little behind the development....
-
Dec 17th, 2002, 11:40 AM
#9
Thread Starter
Junior Member
Here is the code in my Form_onLoad(). The thing is, I tried changing the virtualHeight, virtualWidth and VirtualPageHeight value with many values and nothing changes in my form. It seems like I can scroll like 3-4 times my scroll... Do you have any idea where could be the problem ? Thanks in advance.
---
'\\ Initiate the EventVB link
Set apiLink = New EventVB.APIFunctions
'\\ Start subclassing this window
Set apiWnd = New EventVB.ApiWindow
apiWnd.hWnd = Me.hWnd
With apiWnd
.VirtualHeight = 5
.VirtualWidth = 5
.VirtualPageHeight = 5
.ScrollBars = vbVertical
.AutoScroll = True
End With
apiLink.SubclassedWindows.Add apiWnd
---
-
Dec 17th, 2002, 11:55 AM
#10
Frenzied Member
To make your scrollbar max = 5 pages use:
VB Code:
Option Explicit
Dim WithEvents apiLink As EventVB.APIFunctions
Dim WithEvents apiWnd As EventVB.ApiWindow
Private Sub Form_Load()
'\\ Initiate the EventVB link
Set apiLink = New EventVB.APIFunctions
'\\ Start subclassing this window
Set apiWnd = New EventVB.ApiWindow
apiWnd.hWnd = Me.hWnd
With apiWnd
.VirtualHeight = .Height * 5
.VirtualWidth = .Width
.VirtualPageHeight = .Height
.ScrollBars = vbVertical
.AutoScroll = True
End With
apiLink.SubclassedWindows.Add apiWnd
End Sub
-
Dec 17th, 2002, 12:09 PM
#11
Thread Starter
Junior Member
hmm..
Well it still does'nt work. I made a debug trace on the application and it seems like when I do : .VirtualHeight = .Height * 5, the value of .VirtualHeight do not change on the next line code! As if it was readonly (but if so, an error msgbox should appear no?).
I also tried to put a label in the form and the label did not scroll at all. I don't understand because the textbox and picturebox are scrolling.... but not a label... it this normal?
Thank you again for your time.
-
Dec 17th, 2002, 12:16 PM
#12
Frenzied Member
Labels, shapes and image controls are so-called lightweight controls which do not have a window of their own and therefore cannot be moved by the API..instead you will need to put code in the ApiWindow.VerticalScroll event e.g.:
VB Code:
Private Sub apiWnd_VerticalScroll(ByVal Message As EventVB.enScrollMessages, Position As Long, Cancel As Boolean)
Dim ctThis As Control
For Each ctThis In Controls
If ctThis.Container.hWnd = apiWnd.hWnd Then
If TypeOf ctThis Is Label Or TypeOf ctThis Is Image Then
ctThis.Top = ctThis.Top - (Screen.TwipsPerPixelY * Position)
End If
End If
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|