Microsoft Small Basic

Program Listing: GRR279
' GraphicsWindow Control Panel
' Sample code to control GraphicsWindow

Init()
While "True"
TextWindow.Write("#? ")
num = TextWindow.ReadNumber()
If num = 1 Then
ToggleCanResize()
ElseIf num = 2 Then
target = "Width"
Change()
ElseIf num = 3 Then
target = "Height"
Change()
ElseIf num = 4 Then
target = "Left"
Change()
ElseIf num = 5 Then
target = "Top"
Change()
ElseIf num = 6 Then
target = "Title"
Change()
ElseIf num = 7 Then
target = "BackgroundColor"
Change()
ElseIf num = 8 Then
GraphicsWindow.Show()
ElseIf num = 9 Then
GraphicsWindow.Hide()
ElseIf num = 10 Then
ShowMessage()
Else
Error()
EndIf
EndWhile

Sub Init
Not = "False=True;True=False;"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
TextWindow.WriteLine("GraphicsWindow Control Panel" + CRLF)
help = " #1 Toggle CanResize" + CRLF
help = help + " #2 Change Width" + CRLF
help = help + " #3 Change Height" + CRLF
help = help + " #4 Change Left" + CRLF
help = help + " #5 Change Top" + CRLF
help = help + " #6 Change Title" + CRLF
help = help + " #7 Change BackgroundColor" + CRLF
help = help + " #8 Show" + CRLF
help = help + " #9 Hide" + CRLF
help = help + " #10 ShowMessage" + CRLF
TextWindow.WriteLine(help)
EndSub

Sub ToggleCanResize
GraphicsWindow.CanResize = Not[GraphicsWindow.CanResize]
EndSub

Sub Change
' param target
TextWindow.Write(target + "? ")
value = TextWindow.Read()
If target = "Left" Then
GraphicsWindow.Left = value
ElseIf target = "Top" Then
GraphicsWindow.Top = value
ElseIf target = "Width" Then
GraphicsWindow.Width = value
ElseIf target = "Height" Then
GraphicsWindow.Height = value
ElseIf target = "Title" Then
GraphicsWindow.Title = value
ElseIf target = "BackgroundColor" Then
GraphicsWindow.BackgroundColor = value
EndIf
EndSub

Sub ShowMessage
TextWindow.Write("Text? ")
txt = TextWindow.Read()
TextWindow.Write("Title? ")
title = TextWindow.Read()
GraphicsWindow.ShowMessage(txt, title)
EndSub

Sub Error
TextWindow.ForegroundColor = "Red"
TextWindow.WriteLine("Invalid number " + num)
TextWindow.ForegroundColor = "Gray"
TextWindow.WriteLine(help)
EndSub