Main Logo
Articles   Members Online:
-Article/Tip Search
-News Group Search over 800,000 Borland 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
Delphi: How to make form's client size independent of Windows settings.
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 make form's client size independent of Windows settings. 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
Make form's client size independent of Windows settings. 27-Sep-04
Category
VCL-General
Language
Delphi All Versions
Views
603
User Rating
9
# Votes
2
Replies
0
Publisher:
Lipinski, Zbigniew
Reference URL:
			The possibility of changing the size of various Windows elements
can be a headache to a developer. For instance we have developed
an application which looks very nice on our machine, but when
the awaited day of the first public presentation comes, we cannot 
recognize our thoroughly designed forms: some controls are visible 
only partially, some are overlapped by scrollbars which appeared
out of a sudden on the edges of the forms. The reason is simple:
on our development machine we have classical Windows settings while
on the computer used for the presentation the desktop style is set to 
Windows XP, with wide caption bars which 'eat up' forms' client space
where we have placed our controls.

Below I describe two ways of avoiding such situation:

1. Place a bevel on your form.
2. Set the bevel's Align property to alClient.
3. Set the form's AutoSize property to True and Auto Scroll to false.
4. If you want the form to be sizeable, write a handler for the form's 
   OnShow event, which will set AutoSize back to false when only the form
   appears on the screen.

The other way involves using a non-visible component, which I named 
ClientGuard. Its task is to stream the form's client dimensions
and read them back from a stream when the form is created.
Using this component is extremely easy: you just put it on 
the form. There are no properties to be set or events to be handled.
It is however advisable to set the form's AutoScroll property to false.

The code of the component is quite simple as well:

1   unit ClntGrd;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
7   
8   type
9     TClientGuard = class(TComponent)
10    private
11      procedure ReadClientWidth(Reader: TReader);
12      procedure WriteClientWidth(Writer: TWriter);
13      procedure ReadClientHeight(Reader: TReader);
14      procedure WriteClientHeight(Writer: TWriter);
15      { Private declarations }
16    protected
17      { Protected declarations }
18      procedure DefineProperties(Filer: TFiler); override;
19    public
20      { Public declarations }
21    published
22      { Published declarations }
23    end;
24  
25  procedure register;
26  
27  implementation
28  
29  
30  procedure TClientGuard.ReadClientWidth(Reader: TReader);
31  var
32    w: integer;
33  begin
34    w:=Reader.ReadInteger;
35    if Assigned(Owner) and (Owner is TCustomForm) then
36      (Owner as TCustomForm).ClientWidth:=w;
37  end;
38  
39  
40  procedure TClientGuard.WriteClientWidth(Writer: TWriter);
41  begin
42    Writer.WriteInteger((Owner as TCustomForm).ClientWidth);
43  end;
44  
45  
46  procedure TClientGuard.ReadClientHeight(Reader: TReader);
47  var
48    h: integer;
49  begin
50    h:=Reader.ReadInteger;
51    if Assigned(Owner) and (Owner is TCustomForm) then
52      (Owner as TCustomForm).ClientHeight:=h;
53  end;
54  
55  
56  procedure TClientGuard.WriteClientHeight(Writer: TWriter);
57  begin
58    Writer.WriteInteger((Owner as TCustomForm).ClientHeight);
59  end;
60  
61  
62  procedure TClientGuard.DefineProperties(Filer: TFiler);
63    function DoWrite: boolean;
64    begin
65      Result:=Assigned(Owner) and (Owner is TCustomForm);
66    end;
67  begin
68    inherited;
69    Filer.DefineProperty('ClientWidth', ReadClientWidth,  WriteClientWidth, DoWrite);
70    Filer.DefineProperty('ClientHeight', ReadClientHeight,  WriteClientHeight, 
71  DoWrite);
72  end;
73  
74  procedure register;
75  begin
76    RegisterComponents('MyCompnts', [TClientGuard]);
77  end;
78  
79  
80  end.


			
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
Advertisement


Share this page
Advertisement
Copyright © 2024 by No Limit Solutions LLC