Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Prenvent the user from positioning a form outside the screen work area Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-May-03
Category
VCL-Forms
Language
Delphi All Versions
Views
151
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ernesto De Spirito

How can I prevent the user from moving the form outside screen boundaries to 
guarantee the form is always visible inside the screen work area?

Answer:

We can know if a form has resized with the Resize event (OnResize property), but 
how do we know if a form has moved? Simply by capturing the WM_MOVE Windows message.

In the message event we call "inherited" to let the ancestors of TForm process the 
message. This will update the Left and Top properties that we can use along with 
Width and Height to see if the form is placed within the limits of the screen's 
work area (the portion of the screen not used by the system taskbar or by 
application desktop toolbars) and move it if not. 
1   
2   procedure TfrmMain.OnMove(var Msg: TWMMove);
3   var
4     WorkArea: TRect;
5   begin
6     inherited;
7     if SystemParametersInfo(SPI_GETWORKAREA, 0, @WorkArea, 0) then
8     begin
9       if Left < WorkArea.Left then
10        Left := WorkArea.Left
11      else if Left + Width > WorkArea.Right then
12        Left := WorkArea.Right - Width;
13      if Top < WorkArea.Top then
14        Top := WorkArea.top
15      else if Top + Height > WorkArea.Bottom then
16        Top := WorkArea.Bottom - Height;
17    end;
18  end;


The full source code of this example is available for download: 

http://www.latiumsoftware.com/download/p0020.zip

Copyright (c) 2001 Ernesto De Spiritomailto:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC