Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop Down Menu
#5
Here's a Quick Menu or Button set Demo: in less than <40 LOC for 2 procedures with <20 LOC demo
Code: (Select All)
Option _Explicit
Dim Shared xmax, ymax
xmax = 800: ymax = 600
Screen _NewImage(xmax, ymax, 32)
_ScreenMove 200, 60
Dim Menu$(5), selectNumber%
Menu$(0) = "1st Choice"
Menu$(1) = "2nd Choice"
Menu$(2) = "3rd Choice"
Menu$(3) = "4th Choice"
Menu$(4) = "5th Choice"
Menu$(5) = "Quit"
Do
    Color &HFFFFFFFF, &HFF000000: Cls
    selectNumber% = getButtonNumberChoice%(Menu$())
    Print "You selected: "; Menu$(selectNumber%); "    zzz..."
    Sleep
    If selectNumber% = 5 Then End
Loop


'this works pretty good for a menu of buttons to get menu number
Function getButtonNumberChoice% (choice$())
    Dim As Long ub, b, mx, my, mb
    'this sub uses drwBtn
    ub = UBound(choice$)
    For b = 0 To ub '   drawing a column of buttons at xmax - 210 starting at y = 10
        drwBtn xmax - 210, b * 60 + 10, choice$(b)
    Next
    Do
        While _MouseInput: Wend
        mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
        If mb Then
            If mx > xmax - 210 And mx <= xmax - 10 Then
                For b = 0 To ub
                    If my >= b * 60 + 10 And my <= b * 60 + 60 Then
                        Line (xmax - 210, 0)-(xmax, ymax), , BF
                        getButtonNumberChoice% = b: Exit Function
                    End If
                Next
                Beep
            Else
                Beep
            End If
            _Delay .1
        End If
        _Limit 60
    Loop
End Function

Sub drwBtn (x, y, s$) '200 x 50
    Line (x, y)-Step(200, 50), _RGB32(0, 0, 0), BF
    Line (x, y)-Step(197, 47), _RGB32(255, 255, 255), BF
    Line (x + 1, y + 1)-Step(197, 47), &HFFBABABA, BF
    Color _RGB32(0, 0, 0), &HFFBABABA
    _PrintString (x + 100 - 4 * Len(s$), y + 17), s$
End Sub

Meant to be modified to needs of application.
b = b + ...
Reply


Messages In This Thread
Drop Down Menu - by Dimster - 05-11-2022, 02:35 PM
RE: Drop Down Menu - by SMcNeill - 05-11-2022, 03:21 PM
RE: Drop Down Menu - by Dimster - 05-11-2022, 06:51 PM
RE: Drop Down Menu - by Dimster - 05-12-2022, 05:32 PM
RE: Drop Down Menu - by bplus - 05-12-2022, 06:58 PM
RE: Drop Down Menu - by Dimster - 05-12-2022, 08:32 PM



Users browsing this thread: 3 Guest(s)