289 292




Visual Basic 6 Black Book:Scroll Bars And Sliders
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Handling Scroll Bar Events
You’ve added the scroll bars the Testing Department wanted. You’ve set the scroll bars’ Min, Max, SmallChange, and LargeChange properties. Now how do you add the scroll bars to your program’s code?
When the user changes the setting in a scroll bar, a Change event occurs, and you can react to those changes with an event handler attached to that event. For example, you may use scroll bars to move other controls around on the form (using those controls’ Move method), and when the user changes a scroll bar’s setting, you’ll be informed of the new value in the Change event handler.
Let’s look at an example. We start by adding two scroll bars—a horizontal scroll bar, HScroll1, and a vertical scroll bar, VScroll1—to a form. We set those controls’ Min, Max, SmallChange, LargeChange, and Value properties when the form loads:


Private Sub Form_Load()
VScroll1.Min = 1
VScroll1.Max = 100
VScroll1.LargeChange = 10
VScroll1.SmallChange = 1
VScroll1.Value = 50

HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.LargeChange = 10
HScroll1.SmallChange = 1
HScroll1.Value = 50
End Sub


Now when the user changes the setting in a scroll bar, we can report the new setting in a text box, Text1, simply by using the new setting in the Value property. This looks like the following code. Now we’re handling scroll bar events, as shown in Figure 9.4.

Figure 9.4  Working with scroll bars.


Private Sub HScroll1_Change()
Text1.Text = "Horizontal setting: " & Str(HScroll1.Value)
End Sub

Private Sub VScroll1_Change()
Text1.Text = "Vertical setting: " & Str(VScroll1.Value)
End Sub


Handling Continuous Scroll Bar Events
You can use the Change event to catch the user’s scrolling actions, but there’s another one that’s a lot better for many uses: the Scroll event. When you use the Change event, nothing happens until users are done with their scrolling actions. After the action is completed, the Change event is triggered, and you find out what happened. With the Scroll event, on the other hand, you get continuous updates as the action is happening. This means that you can update the screen immediately to show users the results of their scrolling actions. It’s very useful to be able to update the screen as the user scrolls, especially in cases where you’re scrolling a long document. Imagine trying to scroll 25 pages at a time, only to have to stop scrolling before the screen was updated.
Here’s an example showing how to use the Scroll event; fundamentally, using this event is the same as using the Change event (unless you have an action that should only be performed after the user is done scrolling, in which case you should stick to the Change event). We start the example by adding two scroll bars, a horizontal scroll bar (HScroll1) and a vertical scroll bar (VScroll1), to a form. We set those controls’ Min, Max, SmallChange, LargeChange, and Value properties when the form loads:


Private Sub Form_Load()
VScroll1.Min = 1
VScroll1.Max = 100
VScroll1.LargeChange = 10
VScroll1.SmallChange = 1
VScroll1.Value = 50

HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.LargeChange = 10
HScroll1.SmallChange = 1
HScroll1.Value = 50
End Sub


Next, we just add code to the two scroll bar’s Scroll events to display the new setting in a text box, Text1:


Private Sub HScroll1_Scroll()
Text1.Text = "Horizontal setting: " & Str(HScroll1.Value)
End Sub

Private Sub VScroll1_Scroll()
Text1.Text = "Vertical setting: " & Str(VScroll1.Value)
End Sub


With this code, the text box is continuously updated with the setting of the scroll bars as users manipulate them. This is in sharp contrast to using the Change event, which only occurs when users are finished with their scrolling actions.
Showing And Hiding Scroll Bars
Unlike other controls, there are well-defined times when scroll bars should disappear from your program. If the object you’re scrolling can be entirely visible, there is no need for scroll bars, and you should remove them. (Another option is to disable them by setting their Enabled property to False. Disabled scroll bars appear gray and don’t display a thumb.)
You can make a scroll bar disappear by setting its Visible property to False, and you can make it reappear by setting that property to True. Here’s an example. In this case, we add two scroll bars to a form—a horizontal scroll bar and a vertical scroll bar—and initialize them when the form loads:


Private Sub Form_Load()
VScroll1.Min = 1
VScroll1.Max = 100
VScroll1.LargeChange = 10
VScroll1.SmallChange = 1
VScroll1.Value = 50

HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.LargeChange = 10
HScroll1.SmallChange = 1
HScroll1.Value = 50
End Sub


When the user clicks a command button, we can hide both scroll bars simply by setting their Visible properties to False:


Private Sub Command1_Click()
HScroll1.Visible = False
VScroll1.Visible = False
End Sub


And that’s it—now we can hide and show scroll bars at will. As mentioned, you usually hide scroll bars (or disable them) when the object they scroll is entirely visible and the scroll bars are no longer needed.




Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
289 292 5udhmsrvsecpjfkmgfytpterybiyoiz7p4coooi
289 292
289 292 m2w5x63y6yan64osc2ypwz6oadarjg7gnkpa2vq
demo cgi 289
I CSK 292 06
220 289
SHSpec 292 6308C07 R2H Fundamentals
285 289
SHSpec 289 6307C24 ARC Breaks and the Comm Cycle
292 a

więcej podobnych podstron