Microsoft Small Basic

Program Listing: SLP022
'Variables
TextLeftPosition = 330
TextTopPosition = 430
CanMoveHorizontal = "False"
CanMoveVertical = "False"

'Window
GraphicsWindow.Hide()
GraphicsWindow.Width = 500
GraphicsWindow.Height = 500
GraphicsWindow.Left = (Desktop.Width - 500) / 2
GraphicsWindow.Top = (Desktop.Height - 570) / 2
GraphicsWindow.CanResize = "False"
GraphicsWindow.Title = "Scroll Bars"
GraphicsWindow.FontBold = "False"
GraphicsWindow.FontName = "Microsoft Sans Serif"
GraphicsWindow.BrushColor = "Black"

'Main
AddText()
AddScrollBars()
GraphicsWindow.Show()

'Subroutines - System
'********************
'MouseDown
GraphicsWindow.MouseDown = MouseDown
Sub MouseDown
xDown = GraphicsWindow.MouseX
yDown = GraphicsWindow.MouseY
xPoshHandle = Shapes.GetLeft(hHandle)
yPoshHandle = Shapes.GetTop(hHandle)
xPosvHandle = Shapes.GetLeft(vHandle)
yPosvHandle = Shapes.GetTop(vHandle)

'Gives permision to the handle to be moved horizontaly according to the mouse horizontal position.
If xDown > xPoshHandle And xDown < xPoshHandle + 20 And yDown > yPoshHandle And yDown < yPoshHandle + 20 Then
Sound.PlayClick()
CanMoveHorizontal = "True"
ElseIf xDown > xPosvHandle And xDown < xPosvHandle + 20 And yDown > yPosvHandle And yDown < yPosvHandle + 20 Then
Sound.PlayClick()
CanMoveVertical = "True"
EndIf
EndSub

'MouseMove
GraphicsWindow.MouseMove = MouseMove
Sub MouseMove
xMove = GraphicsWindow.MouseX
yMove = GraphicsWindow.MouseY

'All of the code below happens when you move your mouse.
If CanMoveHorizontal = "True" Then
'Move the handle horizontaly
Shapes.Move(hHandle, xMove - 10, 480)
'Move the text lines horizontaly
Shapes.Move(TxtLine1, -xMove + 340, TextTopPosition)
Shapes.Move(TxtLine2, -xMove + 340, TextTopPosition + 15)
Shapes.Move(TxtLine3, -xMove + 340, TextTopPosition + 30)
ElseIf CanMoveVertical = "True" Then
'Move the handle verticaly
Shapes.Move(vHandle, 480, yMove - 10)
'Move the text lines verticaly
Shapes.Move(TxtLine1, TextLeftPosition, -yMove + 440)
Shapes.Move(TxtLine2, TextLeftPosition, -yMove + 455)
Shapes.Move(TxtLine3, TextLeftPosition, -yMove + 470)
EndIf
EndSub

'MouseUp
GraphicsWindow.MouseUp = MouseUp
Sub MouseUp
CanMoveHorizontal = "False"
CanMoveVertical = "False"
TextLeftPosition = Shapes.GetLeft(TxtLine1)
TextTopPosition = Shapes.GetTop(TxtLine1)
EndSub

'Subroutines - Custom
'********************
'AddText
Sub AddText
Line1 = "Click and drag the handle"
Line2 = "from one of the scroll bars"
Line3 = "in order to move the text."
TxtLine1 = Shapes.AddText(Line1)
TxtLine2 = Shapes.AddText(Line2)
TxtLine3 = Shapes.AddText(Line3)
Shapes.Move(TxtLine1, TextLeftPosition, TextTopPosition)
Shapes.Move(TxtLine2, TextLeftPosition, TextTopPosition + 15)
Shapes.Move(TxtLine3, TextLeftPosition, TextTopPosition + 30)
EndSub

'AddScrollBars
Sub AddScrollBars
GraphicsWindow.PenColor = "DimGray"
GraphicsWindow.BrushColor = "DarkGray"
hBack = Shapes.AddRectangle(480, 20)
Shapes.Move(hBack, 0, 480)
vBack = Shapes.AddRectangle(20, 480)
Shapes.Move(vBack, 480, 0)
GraphicsWindow.PenColor = "DimGray"
GraphicsWindow.BrushColor = "DodgerBlue"
hHandle = Shapes.AddRectangle(20, 20)
Shapes.Move(hHandle, 0, 480)
vHandle = Shapes.AddRectangle(20, 20)
Shapes.Move(vHandle, 480, 0)
EndSub