Object Center in Screen
Im looking at posting some simple code samples and this was one i was asked for.
Its a simple "center" function. It centers any object in the screen.
It can be modified to work across multiple screens (see code).
- Function CenterOBJ(obj)
- ' QUICK and DIRTY "Center" Function
- ' vars:
- ' obj - object name
- '--- if you want to use for multi-monitors change ScreenHeight - VScreenHeight
- sw = system.ScreenWidth
- sh = system.ScreenHeight
- '-- divide these all in 1/2
- scw = sw / 2 '-- screen center width
- sch = sh / 2 '-- screen center height
- ow = desktopx.Object(obj).Width
- oh = desktopx.Object(obj).height
- '-- divide these in 1/2
- ocw = ow / 2 '-- object center width
- och = oh / 2 '-- object center height
- ol = scw - ocw
- ot = sch - och
- desktopx.Object(obj).left = ol
- desktopx.Object(obj).top = ot
- End Function
To use this function simply use the following code:
- Call CenterOBJ("ObjNameHere")
I dont know if people are interested in these types of "tutorials" but if you are, please let me know of some things you would like to see. Im not sure if this has been posted before (I'm sure it has somewhere).