Object Center in Screen
Sunday, January 18, 2009 by RomanDA | Discussion: DesktopX Tutorials
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).
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!