Liberty BASIC includes a "LOCATE" command for moving and resizing controls. This command only works on controls and it only works in windows of type "WINDOW."
nomainwinbutton#main.b,"Move Me",[moveMe],UL,10,10,100,30open"Move a Button"forwindowas#main
#main "trapclose [quit]"wait[quit]close#main:end[moveMe]#main.b "!locate 50 100 200 50"#main.b "I've been moved!"#main "refresh"wait
When the "LOCATE" command is sent to a control that can accept a new label or text, we must precede the command with a ! character as we did above, or the command string is simply displayed on the control and not acted on. Note the difference in the two lines below. The first line is a command that instructs the button to change its size and location. The second line changes the caption on the button.
#main.b "!locate 50 100 200 50"#main.b "I've been moved!"
Don't forget to issue a "REFRESH" command to cause the window display to be updated after moving a control.
MoveWindow API
We can move and resize any window or control with the MoveWindow API call. The coordinates for the x and y locations of a window are relative to the upper left corner of the desktop. If the API call is used to move or resize a control, the coordinates are relative to the upper left corner of the window's workspace, which is called the Client Area.
Liberty BASIC does not currently have a native function for moving or resizing an open window. It also does not allow us to move or resize controls contained in windows that are not of type "WINDOW." We must use an API call to change the location and size of windows and of controls not in "WINDOW" type windows. \
To move or resize a window, use the handle of the window obtained with the HWND() function.
hMain =HWND(#main)calldll#user32,"MoveWindow",_
hMain asulong, _ 'window handle10aslong,_ 'x location of window20aslong,_ 'y location of window730aslong,_ 'desired width of window590aslong,_ 'desired height of window1aslong,_ 'repaint flag,0=false,1=true
ret aslong'nonzero=success
To move or resize a control, use the handle of the control obtained with the HWND() function.
hButton =HWND(#main.b)calldll#user32,"MoveWindow",_
hButton asulong, _ 'control handle50aslong,_ 'x location of control150aslong,_ 'y location of control200aslong,_ 'desired width of control50aslong,_ 'desired height of control1aslong,_ 'repaint flag,0=false,1=true
ret aslong'nonzero=success
Demo
nomainwinbutton#main.b,"Move Me",[moveMe],UL,10,10,100,30button#main.move,"Move Window",[moveWindow],UL,120,10,100,30open"Move a Button"forwindowas#main
#main "trapclose [quit]"wait[quit]close#main:end[moveMe]#main.b "I've been moved!"
hButton =HWND(#main.b)calldll#user32,"MoveWindow",_
hButton asulong, _ 'control handle50aslong,_ 'x location of control150aslong,_ 'y location of control200aslong,_ 'desired width of control50aslong,_ 'desired height of control1aslong,_ 'repaint flag,0=false,1=true
ret aslong'nonzero=successwait[moveWindow]
hMain =HWND(#main)calldll#user32,"MoveWindow",_
hMain asulong, _ 'window handle10aslong,_ 'x location of window20aslong,_ 'y location of window730aslong,_ 'desired width of window590aslong,_ 'desired height of window1aslong,_ 'repaint flag,0=false,1=true
ret aslong'nonzero=success'we'll only move window once, then disable button #main.move "!disable"wait
Table of Contents
Moving or Resizing a Window or Control
Native LOCATE Command
Liberty BASIC includes a "LOCATE" command for moving and resizing controls. This command only works on controls and it only works in windows of type "WINDOW."When the "LOCATE" command is sent to a control that can accept a new label or text, we must precede the command with a ! character as we did above, or the command string is simply displayed on the control and not acted on. Note the difference in the two lines below. The first line is a command that instructs the button to change its size and location. The second line changes the caption on the button.
Don't forget to issue a "REFRESH" command to cause the window display to be updated after moving a control.
MoveWindow API
We can move and resize any window or control with the MoveWindow API call. The coordinates for the x and y locations of a window are relative to the upper left corner of the desktop. If the API call is used to move or resize a control, the coordinates are relative to the upper left corner of the window's workspace, which is called the Client Area.Liberty BASIC does not currently have a native function for moving or resizing an open window. It also does not allow us to move or resize controls contained in windows that are not of type "WINDOW." We must use an API call to change the location and size of windows and of controls not in "WINDOW" type windows. \
To move or resize a window, use the handle of the window obtained with the HWND() function.
To move or resize a control, use the handle of the control obtained with the HWND() function.
Demo