How to Create Your Own Slider Bar in Visual Basic 3.0
ID: Q113948
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for Windows, version 3.0
SUMMARY
This article describes how to make your own Slide control similar to the
Windows Media Player's slide bar in Windows Accessories group or the
Scroll bar in Visual Basic.
MORE INFORMATION
Visual Basic for Windows supplies Horizontal and Vertical Scroll bars, but
it does not offer the ability to customize the appearance of these Scroll
bars. The example code in this article uses Picture and Image controls to
create a Slide bar which can be customized to include Bitmaps, background
colors, and more.
Step-by-Step Example
- Start a new project in Visual Basic. Form1 is created by default.
- Add a timer (Timer1) and a picture control (Picture1) to Form1.
- Select Picture1 by clicking it once. Now select the image control from
the Toolbox and draw it onto Picture1. This new image control (Image1)
should be contained by Picture1. You should not be able to drag Image1
off Picture1.
- Add the following code to the appropriate event procedures in Form1:
' Add the following to the general declarations section:
Dim Mouse_Button As Integer
Dim Mouse_X As Single
Dim PicFrame As Integer
Sub Form_Load ()
Timer1.Enabled = False
Timer1.Interval = 10
Image1.Picture = LoadPicture("C:\VB\ICONS\ELEMENTS\EARTH.ICO")
PicFrame = 2 * Screen.TwipsPerPixelY
Image1.Top = 0
Image1.Left = 0
Picture1.Height = Image1.Height + PicFrame
End Sub
' Enter the following two lines as one, single line of code:
Sub Image1_MouseDown (Button As Integer, Shift As Integer, X As Single,
Y As Single)
Timer1.Enabled = True
Mouse_Button = Button
Mouse_X = Image1.Left + X
End Sub
' Enter the following two lines as one, single line of code:
Sub Image1_MouseMove (Button As Integer, Shift As Integer, X As Single,
Y As Single)
Mouse_Button = Button
Mouse_X = Image1.Left + X
End Sub
' Enter the following two lines as one, single line of code:
Sub Image1_MouseUp (Button As Integer, Shift As Integer, X As Single,
Y As Single)
Timer1.Enabled = False
Mouse_Button = Button
Mouse_X = Image1.Left + X
End Sub
Sub Timer1_Timer ()
Dim TempLeft As Integer
If Mouse_Button = 1 Then
TempLeft = Image1.Left
TempLeft = Mouse_X - TempWidth / 2
If TempLeft + Image1.Width > Picture1.Width Then
TempLeft = Picture1.Width - Image1.Width - PicFrame
End If
If TempLeft < 0 Then TempLeft = 0
End If
If Image1.Left <> TempLeft Then Image1.Left = TempLeft
End Sub
- From the Run menu, choose Start (ALT, R, S), or press the F5 key to run
the program.
Select the Earth icon with your Mouse and hold the mouse button down while
you move the mouse. The Earth icon will move left and right within the
Picture control as you move your mouse.
Additional query words:
3.00 slider
Keywords :
Version :
Platform :
Issue type :
|