Form not displaying correctly on Laptop

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
rayhall
Posts: 4
Joined: Sat Nov 21, 2020 12:55 am

Form not displaying correctly on Laptop

Post by rayhall »

I have a Application that will not fully display on a laptop with a smaller screen.
Can someone please explain what I have done wrong when writing this application, Here are some screen shots showing the problem.

Ray.
Correct display as expected on PC screen
Correct display as expected on PC screen
SimulatorGood.png (64.88 KiB) Viewed 392 times
Laptop full screen
Laptop full screen
SIM 1.2_1.jpg (194.17 KiB) Viewed 392 times
Laptop display minimized
Laptop display minimized
SIM 1.2_2.jpg (241.21 KiB) Viewed 392 times
smd
BCBJ Guru
BCBJ Guru
Posts: 139
Joined: Sat Nov 29, 2014 8:02 pm
Location: Las Vegas
Contact:

Re: Form not displaying correctly on Laptop

Post by smd »

Aspect ratio of the screens. The screens are probably different resolutions.
-----------------------------
Scott
rayhall
Posts: 4
Joined: Sat Nov 21, 2020 12:55 am

Re: Form not displaying correctly on Laptop

Post by rayhall »

Aspect ratio of the screens. The screens are probably different resolutions.
Thank you.
What can I do to make the form adjust for the differences on create or draw.
Ray.
HsiaLin
BCBJ Master
BCBJ Master
Posts: 336
Joined: Sun Jul 08, 2007 6:29 pm

Re: Form not displaying correctly on Laptop

Post by HsiaLin »

I had this problem once myself, the only option you have is to make your form smaller
if you have a laptop with an unusual resolution....as far as i know.
User avatar
2ffat
Forum Mod
Forum Mod
Posts: 451
Joined: Wed Jun 23, 2004 7:07 am
Location: South Hill, VA
Contact:

Re: Form not displaying correctly on Laptop

Post by 2ffat »

I will search my archives. It seems to me that there was an article on how to create a form that would change it's size. It may take me awhile as I have a long week's worth of work but only a short week's worth of time to do it.
James P. Cottingham

Look at me still talking
when there is science to do.
rayhall
Posts: 4
Joined: Sat Nov 21, 2020 12:55 am

Re: Form not displaying correctly on Laptop

Post by rayhall »

I have found this code for Delphi. I have tried unsuccessfully to convert it to C++Builder. Can someone please help do this.
Ray.

**************************************************************************
Technical Information Database

TI944D.txt Form display with different screen resolutions.
Category :VCL
Platform :All
Product :Delphi All

Description:
When designing forms, it is sometimes helpful to write the code
so that the screen and all of its objects are displayed at the
same size no matter what the screen resolution is. Here is
some code to show how that is done:

Code: Select all

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.  You can iterate over each child
control's font to adjust its size as necessary.  This can be
done as follows:

type
  TFooClass = class(TControl); { needed to get at protected }
                               { font property } 

var
  i: integer;
begin
  for i := ControlCount - 1 downto 0 do
    TFooClass(Controls[i]).Font.Size := 
        (NewFormWidth div OldFormWidth) * 
        TFooClass(Controls[i]).Font.Size;
end;
HsiaLin
BCBJ Master
BCBJ Master
Posts: 336
Joined: Sun Jul 08, 2007 6:29 pm

Re: Form not displaying correctly on Laptop

Post by HsiaLin »

I tried this component and it works well. I do not know if it will work
the way you want it to but it seems as it would. Just follow the
instructions once you have made it into a package for install to
your tool palette. If your form is sizeable with the mouse it should
do what you need it to.

https://github.com/pgiacomo69/TFormResizer
rayhall
Posts: 4
Joined: Sat Nov 21, 2020 12:55 am

Re: Form not displaying correctly on Laptop

Post by rayhall »

Thank you. The problem is it is another Delphi code example. It seams no one uses C++Builder. I do not use Delphi and do not understand the code.
Ray.
HsiaLin
BCBJ Master
BCBJ Master
Posts: 336
Joined: Sun Jul 08, 2007 6:29 pm

Re: Form not displaying correctly on Laptop

Post by HsiaLin »

You make a new package in c++ and add the pas to it and install it as a item in your tool palette.
rlebeau
BCBJ Author
BCBJ Author
Posts: 1737
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: Form not displaying correctly on Laptop

Post by rlebeau »

rayhall wrote: Sat Nov 28, 2020 5:41 pm The problem is it is another Delphi code example. It seams no one uses C++Builder.
Plenty of people use C++Builder. It is just more common to see examples and components written in Pascal because C++Builder includes a Delphi compiler, so code can be written one time in Pascal and used in both Delphi and C++Builder projects without needing to be translated.
Remy Lebeau (TeamB)
Lebeau Software
rlebeau
BCBJ Author
BCBJ Author
Posts: 1737
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: Form not displaying correctly on Laptop

Post by rlebeau »

rayhall wrote: Fri Nov 27, 2020 10:11 pm I have found this code for Delphi. I have tried unsuccessfully to convert it to C++Builder. Can someone please help do this.
Try this:

Code: Select all

const int ScreenWidth = 800; /* I designed my form in 800x600 mode.*/
const int ScreenHeight = 600;

#pragma resource "*.DFM"

// better: use the constructor's actual constructor instead...
// __fastcall TForm1::TForm1(TComponent Owner) : TForm(Owner)
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	Scaled = true;
	if (Screen->Width != ScreenWidth)
	{
		Height = Height * Screen->Height / ScreenHeight;
		Width = Width * Screen->Width / ScreenWidth;
		ScaleBy(Screen->Width, ScreenWidth);
	}
}

Code: Select all

class TFooClass : public TControl /* needed to get at protected Font property */ 
{
public:
	__property Font;
};

for(int i = ControlCount - 1; i >= 0; --i) {
	((TFooClass*)(Controls[i]))->Font->Size = (NewFormWidth / OldFormWidth) * ((TFooClass*)(Controls[i]))->Font->Size;
}
Remy Lebeau (TeamB)
Lebeau Software
Post Reply