1. Home
  2. Computing & Technology
  3. Delphi Programming

Understanding ScreenToClient and ClientToScreen Delphi methods

By Zarko Gajic, About.com

ScreenToClient and ClientToScreen Delphi methods

ScreenToClient and ClientToScreen Delphi methods

Every Delphi control, descendant of the TControl class, exposes two methods you can use to convert point coordinates: ScreenToClient and ClientToScreen.

In screen coordinates (0, 0) corresponds to the upper left corner of the screen.

In client area coordinates (0, 0) corresponds to the upper left corner of the control's client area.

ScreenToClient

Declared as
function ScreenToClient(const Point: TPoint): TPoint;
ScreenToClient method is used when you need to convert a point in screen coordinates to local, or client area, coordinates.

For example, the Mouse.CursorPos returns the position of the mouse cursor in screen coordinates.

To get the coordinates of the mouse "inside" a Delphi control, you can convert this value using

Control.ScreenToClient(Mouse.CursorPos).

ClientToScreen

Declared as
function ClientToScreen(const Point: TPoint): TPoint;
ScreenToClient translates a given point from client area coordinates to global screen coordinates.

An Example

A great example of using the ScreenToClient method is when you need to know which TStatusBar Panel was clicked.

Delphi tips navigator:
» Use an Icon for a Glyph on a TBitBtn Delphi control with the help of TImageList
« Displaying the Percentage Character in Delphi's Format function

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips
  7. Understanding ScreenToClient and ClientToScreen Delphi VCL methods

©2009 About.com, a part of The New York Times Company.

All rights reserved.