Solved

Forms in different resolutions

Posted on 1998-10-22
54
291 Views
Last Modified: 2010-05-18
Can any one send me the code/free component for designing a form to cater for all resolutions (specially for lower resolutions)
Regards
venks
0
Comment
Question by:venks
  • 20
  • 14
  • 7
  • +4
54 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343979
hi venks,

there are several ones, but i don't know if they work properly...

Zif.
0
 
LVL 1

Author Comment

by:venks
ID: 1343980
Dear Tom
Do let me know.I will try them out.I also have tried out some.But they are hopeless .Do you have any idea waht is the difficult part in arriving at a good solution.
Regards
venks
t

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343981
It's easy to do such a thing. I'm in school now, but when I get back i can make one for you... of course if you haven't already found one.... Talk to to you in couple of hours..

Cheers,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343982
Hi,

well, i don't know if it is so easy, I never tried it, but I think there can be some problems. The form will be relatively easy but think on the components on the form : think on grids, fonts, etc. Even think on the fact that windows NT and 95/98? have different drawing ways. (e.g. a grid in NT will be drawn differently on a 95)

here are some :

http://torry.rimini.com/vcl/forms/resscale.zip
http://torry.rimini.com/vcl/forms/scale.zip (no source I guess, but FW)
http://torry.rimini.com/vcl/forms/tbres.zip (SW)
http://www.delphipages.com/edit/count.cfm?comID=286&Link=uploads%2FForms%5FApplication%2Felastfrm%2Ezip

and if these don't help, viktor will help (I'm sure of it)

Zif.
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1343983
venks

Here is a quick code snippet...

implementation
const
  ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
  ScreenHeight: LongInt = 600;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  scaled := true;
  if (screen.width <> ScreenWidth) then
  begin
    height := longint(height) * longint(screen.height) div ScreenHeight;
    width := longint(width) * longint(screen.width) div ScreenWidth;
    scaleBy(screen.width, ScreenWidth);
  end;
end;

Then, you will want to have something that checks to see that
the font sizes are OK.  Before you change the font's size, you
would need to ensure the object actually has a font property.  
This can be done as follows:

uses typinfo;

var
  i: integer;
begin
  for i := componentCount - 1 downtto 0 do
    with components[i] do
    begin
      if GetPropInfo(ClassInfo, 'font') <> nil  then
        font.size := (NewFormWidth DIV OldFormWidth) * font.size;
    end;
end;
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343984
Hello y'all...

Just to point a few things out.... The component containts almost what Boris gave you. YOu need to chech the ScaleBy() and the Font stuff.... In the code where Boris checks not the fonts but the furst part for the component...you need to set the form that the component is on to be OwnerForm.AutoSize := False; //Not sure for the OwnerForm but it's something similar.... Or you could do,,,,

if Owner = TForm then
TForm(Owner).AutoSize := False;

Maybe something like that....

Another thing with the Fonts there is a lot easier way to do so.... You simply do..

OwnerForm.Fonts.Pitch := fpVariable;

That's all. Inprise have thought about that so that's all you need to do about the fonts...

Hope this helps!

Regards,
Viktor Ivanov

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343985
Ooopppss...... There is a mistake. Don't touch the property AutoSize as I showed before...   OwnerForm.AutoSize := False;

Instead use the OwnerForm.AutoScroll := False; Change the property AutoScroll to False and don't touch the AutoSize... Sorry for the misstyping...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1343986
For all
Thanks.I will test the things out and come back later.AS far as the points are concerned I think Boris deserves it.

Dear Boris
Can you give me the complete code including what viktorne's suggestions
regards
venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343987
Hello Venks....

This code for the component should look something like this....

unit Scaler;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
   ScreenWidth  : Integer = 800; //If you don't want to declare constants you'd have to have a
   ScreenHeight : Integer = 600;//property for each of these two so you can declare it at //designtime
type
  TScaler = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    constructor Create(AOwner : TComponent);override;
    procedure Loaded;override;
  published
    { Published declarations }
  end;
procedure Register;
implementation
constructor TScaler.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
end;
procedure TScaler.Loaded;
begin
  Inherited;
  if not(csDesigning in ComponentState) then
    if Owner is TForm then
    with TForm(Owner) do begin
      Scaled := true;
      Font.Pitch := fpVariable;
      AutoScroll := False;
      if (Screen.Width <> ScreenWidth) then begin
        Height := Height * Screen.Height div ScreenHeight;
        Width := Width * Screen.Width div ScreenWidth;
        ScaleBy(Screen.Width, ScreenWidth);
      end;
    end;
end;
procedure Register;
begin
  RegisterComponents('Samples', [TScaler]);
end;
end.

Hope this helps... I wrote it in Delphi IDE but haven't tested it if it works since I don't want to cahnge my resolutions and stuff.... Please check it out and hope it works :-)

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1343988
Thanks Viktor
Now I am really confused as to whom to award the points.
Every one is so helpful.IF i can get meet all the guys in delphi exchange i will give them all a big treat(even if i go bankrupt)
I have really learnt that sharing knowledge is greater than mere
money.
We have a saying in Hindu custom that
"Knowledge comes first
'Delphi is proving that
I will try out and come back soon
Thanks
vebks
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1343989
venks

yip what viktornet said...(the component) again :-)

Later
BoRiS

I think myself a viktornet should get together and develop as we seem to have the same ideas as to how things should look and run...

viktornet should I answered the question and give you half, I'll post a question for you...

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343990
Don't worry about the points... Everything is cool...Just answer the question ;->

Cheers,
Viktor
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343991
btw- Venks... Did you try the code for the component in different resolutions??? If yes, did it work????

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:venks
ID: 1343992
Dear Viktor
I am sorry but it did not work.To compare it  i tried with a component given out by zifnab and it seems to work.Unfortunately the source code was not availble for the component.
Is there some thing else with the hardware part that is to be taken into consideration.
Actually this problem is a universal problem and the solution should have come from Borland(inprise) itself.
Any how I will keep on trying.Hope you all do the same.
I will post the points once it is answered.
Regrds
venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343993
unit Scaler;

     interface

     uses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
     Dialogs;
     const
        ScreenWidth  : Integer = 800; //If you don't want to declare constants
     you'd have to have a
        ScreenHeight : Integer = 600;//property for each of these two so you can
     declare it at //designtime
     type
       TScaler = class(TComponent)
       private
         FAllScaled : Boolean;
       protected
         { Protected declarations }
       public
         constructor Create(AOwner : TComponent);override;
         procedure Loaded;override;
       published
         { Published declarations }
       end;
     procedure Register;
     implementation
constructor TScaler.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
  AllScaled := False;
end;
procedure TScaler.Loaded;
begin
  Inherited;
  if not(csDesigning in ComponentState) then
    if Owner is TForm then
    with TForm(Owner) do begin
      Font.Pitch := fpVariable;
      if not(AllScaled)and((Screen.Width<>ScreenWidth)or(Screen.Height<>ScreenHeight))then       begin
        Scaled := True;
        AutoScroll := False;
        ScaleBy(Screen.Width, ScreenWidth);
        AllScaled := True;
      end;
   end;
end;
procedure Register;
begin
  RegisterComponents('Samples', [TScaler]);
end;
end.

Here is a new version that works... The problem is that this thing doesn't work because your screen Width and Height is 800X600  ....Mine is same... When I changed the constants to 400 and 300 respectively it works and the form is resclaled the right way and the fonts are changed to the appropriate one... Got it?? So if the Width and Height of the screen are not as the ones you have determined in your case the ones that you have build the component... then the Form will be resized otherwise it won't ....

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1343994
Dear Viktor
Have a look at the following component
http://torry.rimini.com/vcl/forms/scale.zip (no source I guess, but FW) (The url was given by zifnab) and let me know what you think about it
In the mean time i will try out you new code too
regards
venks

0
 
LVL 4

Expert Comment

by:dwwang
ID: 1343995
Hi, this is a simple answer if you do not insist on using "forms":

Just set the borderstyle to bsDialog and Delphi will do all the scales for you.

If it is not (all) what you want, just reject this answer,OK?
0
 
LVL 1

Author Comment

by:venks
ID: 1343996
Dear dwwang
Thanks for the answer.But that is not what i want
regards
venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343997
I didn't want to install the component....it's too much work... Anyway, did you try the new code... try changing the ScreenWidth to 400 and ScreenHeight to 300 so as if you worked on your project at resolution 400X300... And now that your real resolution is 800X600 you;ll see that your form enlarges to the resolution.... After you finish the experiment change the values of ScreenWidth and ScreenHeight to 800 and 600 respectively...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1343998
Dear Viktor
I tried out your suggestion and ie  putting 400 X 300 and the form scaled up properly ie at 800 X 600 (My screen resolution)

Then i went to the component code of scaler.pas and amended the constants to 400 and 300 respectively.
I compiled the application(in 800 X 600 mode)  and tried  to run at a lower resoution.But the form did not down scale,Many of the controls went out of the screen and scrolling had to be resorted to.
That is the latest position.
Thanks for the help
regards
venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343999
Maybe you'd have to see if the width is greater or less..... so the code might go as follows...

Instead of this code....
if
 not(AllScaled)and((Screen.Width<>ScreenWidth)or(Screen.Height<>ScreenHeight))then       begin

         Scaled := True;
         AutoScroll := False;
         ScaleBy(Screen.Width, ScreenWidth);
         AllScaled := True;
       end;

use this one....

if not(AllScaled)and((Screen.Width<>ScreenWidth)or(Screen.Height<>ScreenHeight))then       begin
         Scaled := True;
         AutoScroll := False;
if Screen.Width < ScreenWidth then
         ScaleBy(Screen.Width, ScreenWidth)
else ScaleBy(ScreenWidth, Screen.Width);
         AllScaled := True;
   end;

Give it a shot and tell me how everything goes....

Cheers,
Viktor
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344000
hi !

I have a component, which is a panel. and when you drop something on it, and you
resize the form, the component that are on the panel are resized too.

This is the code:   ( Install it as a new component )

unit ElasticPanel;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls;

type
  TElasticPanel = class( TPanel )
  private
     FHorz, FVert: boolean;
     nOldWidth, nOldHeight: integer;
     bResized: boolean;
  protected
     procedure WMSize( var message: TWMSize ); message WM_SIZE;
  public
     nCount: integer;
     constructor Create( AOwner: TComponent ); override;
  published
     property ElasticHorizontal: boolean read FHorz write FHorz default
TRUE;
     property ElasticVertical: boolean read FVert write FVert default
TRUE;
  end;

procedure Register;

implementation

constructor TElasticPanel.Create( AOwner: TComponent );
begin
  inherited Create( AOwner );
  FHorz := TRUE;
  FVert := TRUE;
  nOldWidth := Width;
  nOldHeight := Height;
  bResized := FALSE;
end;

procedure TElasticPanel.WMSize( var message: TWMSize );
var
  bResize: boolean;
  xRatio: real;
  i: integer;
  ctl: TWinControl;
begin
  Inc( nCount );
  if Align = alNone then
     bResize := TRUE
  else
     bResize := bResized;
  if not ( csDesigning in ComponentState ) and bResize then
     begin
        if FHorz then
           begin
              xRatio := Width / nOldWidth;
              for i := 0 to ControlCount - 1 do
                 begin
                    ctl := TWinControl( Controls[i] );
                    ctl.Left := Round( ctl.Left * xRatio );
                    ctl.Width := Round( ctl.Width * xRatio );
                 end;
           end;
        if FVert then
           begin
              xRatio := Height / nOldHeight;
              for i := 0 to ControlCount - 1 do
                 begin
                    ctl := TWinControl( Controls[i] );
                    ctl.Top := Round( ctl.Top * xRatio );
                    ctl.Height := Round( ctl.Height * xRatio );
                 end;
           end;
     end
  else
     begin
        nOldWidth := Width;
        nOldHeight := Height;
     end;
  bResized := TRUE;
  nOldWidth := Width;
  nOldHeight := Height;
end;

procedure Register;
begin
  RegisterComponents('Standard', [TElasticPanel]);
end;

end.

_______

Of course, the code is not mine..
hope it helps in some way

bryan =)

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344001
hey, look in here:

http://www.inprise.com/devsupport/delphi/techdocs/tis/ti2861.html

( this is from ShadowHawk )

bryan

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344002
Forgot to say that you have to set the panel align to AllClient.

bryan =)


0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344003
hey viktornet:

I tried to install your component, TScaler
and got this error:

'Undeclared Identifier' at this line:

procedure Register;
implementation
 constructor TScaler.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
  AllScaled := False;  <----------------------------------- HERE
end;

bryan

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344004
viktornet:

I think the error was here:

type
           TScaler = class(TComponent)
           private
             FAllScaled : Boolean;   <------------- I changed FAllScaled for AllScaled

Both of the Components work. The one from 22-Oct, and the one from 23.oct.
what's the difference ? which is better ?

bryan

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344005
Both are good, but not optimized at all.... Just a simple code I threw in two minutes...

Cheers,
Viktor
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Accepted Solution

by:
BoRiS earned 20 total points
ID: 1344006
venks

here is my answer to the question...glad my code worked...

Hi all, sorry I havn't been with this thread a while my ISDN wnet down for a couple of days
but I'm back up and running.

Viktornet
I see you have been busy here.. :-)

Later
BoRiS
0
 
LVL 1

Author Comment

by:venks
ID: 1344007
Dear Boris
I am awarding hte points to you.But at the same time i want to award the points to victornet also because he has been at it.Hence i a m awarding the points to him by throwing him a separate question.
Thanks to both of you
regards
venks
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344008
venks

That is perfect I think victornet deserves the points he did a great job here...

Later
BoRiS
0
 
LVL 1

Author Comment

by:venks
ID: 1344009
Dear Viktor
I spent considerable time trying it out in different resolutions.
But it did not work at all.
I expected that the components will resize automatically to show all the controls. like listbox,dbgrid etc.But all the controls were not visible in lower resolution(in original they fitted into one screen at 800 X 800 pixels)
Brian has commeted that it has worked on his system
May be he can give additional inputs
This session has been very long even though it was worth 25 points only.Thanks
regards
venks

0
 
LVL 1

Author Comment

by:venks
ID: 1344010
Dear Viktor
Treat my last message as cancelled.It works perfectly and really great.Now i can go to my boss and show off whereas it was your idea.
Only thing to remember is that name labels in such a manner that
the edges do not cut the characters.Best thing is to use space
as the first character.
On the whole it is very good.
Once again sorry for the last message where i had commented that it does not work as expected.It was my mistake
Thanks and regards
venks
0
 
LVL 1

Author Comment

by:venks
ID: 1344011
For all
The accepted answer is not the comletly cotrrec answer.Go through Viktornets comments to ger the right solution
0
 
LVL 1

Author Comment

by:venks
ID: 1344012
For all
The last comment had lots of spelling mistakes and i had accidetally hit the submit button
The accepted answer is not the completly correct answer.Go through Viktornets comments to ger the right solution
regards
venks
 
 
   
 

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1344013
hey, did anyone check my component ?

bryan

0
 
LVL 1

Author Comment

by:venks
ID: 1344014
No i did not since viktors compo has done the trick
Thanks anyway
Venks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344015
Venks,

 Still, is the solution working for all components on the form? How does it react on NT? How are fonts realised?

 No offence, I'm just curious.

Zif.
0
 
LVL 1

Author Comment

by:venks
ID: 1344016
Dear Zifnab
Yes it does work for all components.Fonts are also sized properly.Only thing use Truetype fonts.I uses arial size 10.
It works for all resolutions .The component size is very small and no properties are any thing like that.But it works
According to victor it is not optimised.May be you can give it a try to optimise it.But i am very happy with the way things are.

I have not tried it on NT).i dont have one.If some one can upload it to DSR or Torry's it will do a lot of good.

regards
venks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344017
can you send the code? 10x tom.deprez@uz.kuleuven.ac.be
0
 
LVL 1

Author Comment

by:venks
ID: 1344018
Dear Tom
I am sending it to you.
regards
venks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344019
Venks, thanks a lot!
0
 
LVL 1

Author Comment

by:venks
ID: 1344020
Dear Tom
My mail delivery system has not accepted you e mail address
10xtom.deprez@uz.kuleuven.ac.be
Please check your e mail address once again and let me know.then i will post it again
regrds
venks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344021
venks,

It's because it is : tom.deprez@uz.kuleuven.ac.be

10x = tenx = thanks. 10x for sending it :-)

Regards, Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344022
Hello guys.. Just cam back from school.. Happpy to hear it finally worked...

btw- Would you mind sending the whole source to me since I wouldn't like to go throuhg all the comments and join the pieces together. I'd like to have it so if I need it some time in the future I don't have to do the code again.... If you decide to send it to me just e-mail it to me,.. See my profile for my e-mail address...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1344023
Dear Tom and viktor
I just sent the code
regards
venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344024
Hello venk!

I didn't receive nothing. Wonder why??
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344025
Hi venks, I've received it. 10x
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344026
Same here ;-)

You haven't added anything new... I though you would to get a better use out of it...
0
 
LVL 1

Author Comment

by:venks
ID: 1344027
I did not add any thing since it is meeting all my requirements
I a  liitle busy now .and i if i add anything i will post it to you
Venks
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344028
no problem... =)

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:venks
ID: 1344029
I am unchecking the email notification for this question for self
venks
0
 

Expert Comment

by:tong111797
ID: 8371135
Can someone post the final version ?
I get very confuse my poor english.

Thanks!

tong@fanwap.com
0
 

Expert Comment

by:tong111797
ID: 8373426
I have modify your code and work now....
I use percent value...so you have to calculate in your form
for automatic adjust...I use percent value because I can
adjustable manually.

Thanks!

--------------------------------------------------------


unit Scale;

interface

uses
  Windows, Classes, Graphics, Controls, Forms;

type
  TScale = class(TComponent)
  private
    FPercent : smallint;
  public
    constructor Create(AOwner: TComponent);override;
    destructor  Destroy; override;
    procedure ScaleNow;
  published
    property ScaleByPercent: smallint read FPercent write FPercent;
  end;

Procedure Register;

implementation

constructor TScale.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  FPercent     := 100;
end;

procedure TScale.ScaleNow;
begin
  if not (csDesigning in ComponentState) then
     if Owner is TForm then
        with TForm(Owner) do
        begin
             if FPercent <> 100 then
             begin
                Font.Pitch := fpVariable;
                Scaled     := True;
                AutoScroll := False;
                ScaleBy(FPercent,100);
             end;
        end;
end;

destructor TScale.Destroy;
begin
  Inherited Destroy;
end;

procedure Register;
begin
  RegisterComponents('AddOn', [TScale]);
end;

end.
0
 
LVL 1

Author Comment

by:venks
ID: 8377730
This is a 5 year old question.I am glad some one still find it useful
venks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now