Solved

How to align the TImage with the main form.

Posted on 2006-11-07
7
290 Views
Last Modified: 2010-05-18
Dear Experts,

I am making a telnet-app and I am using an TImage to display the data.
I have put a little example on my site. If you have downloaded my example
maximize it and typ some letters, and you'll see the letters on the TImage.

You see in my example that the Timage is not fully aligned with the main form.
and that's my problem. How can I get the TImage align with the mainform
and when the user resize the form that the Timage resize with it, and without
deforming the font, because when you set the Property Stretch to True and
Align to AlClient, the TImage will be fully aligned, but the font will be deformed
(that's because the font will be stretched too).

Does someone know how to make the TImage fully Aligned with the main form
and without deforming the font?

My site:
http://members.home.nl/peterkiers/
(Beneath the Under Construction-bar you see a floppy-disk, that's my example)

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17894381
procedure TForm1.FormCreate(Sender: TObject);
begin
  image1.align := alClient;
  image1.Stretch := False;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  image1.Picture.Bitmap.Width := Image1.Width;
  image1.Picture.Bitmap.Height := Image1.Height;
end;

Only issue is if you shrink the form smaller than the required width/height, then you need to repaint the image.

The solution would be to hold the "Real" image in a memory bitmap, and do a Canvas.CopyRect to the image1, so when you shirnk, and expand again, you can see the entire image again

  public
    { Public declarations }
    fullbitmap: TBitmap;
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fullbitmap := TBitmap.create;
  fullbitmap.LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Splash\256Color\shipping.bmp');
  image1.align := alClient;
  image1.Stretch := False;
  image1.picture.Assign(fullbitmap);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  fullbitmap.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
var
  Rect: TRect;
begin
  image1.Picture.Bitmap.Width := Image1.Width;
  image1.Picture.Bitmap.Height := Image1.Height;
  Rect.Top := 0; Rect.Left := 0;
  Rect.Right := image1.Picture.Bitmap.Width;
  Rect.Bottom := image1.Picture.Bitmap.Height;
  image1.Picture.Bitmap.Canvas.CopyRect(rect, fullbitmap.Canvas, Rect);
end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 17894484
Hi, thank you for your response.
But the TImage still doesn't resize with the main form.

Peter.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17894839
have you set the form's "OnResize" event to the one above?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:peterkiers
ID: 17894847
Yes.
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17896123
You probably put the TImage on a panel or something.
Try to create it on runtime, and assign the properties TheRealLoki suggested above.
It should work
0
 
LVL 28

Accepted Solution

by:
TName earned 500 total points
ID: 17898195
>You probably put the TImage on a panel or something
Yes, a scrollbox.

First of all, set Scrollbox1.DoubleBuffered:=True; in the OnCreate of the form, otherwise testing with the image set to  alClient can be a real pain ;)

If I understand it correctly, you want the WHOLE image to resize with the form and to be displayed (without deformation) . And this is where the problems start.
You have an imaginary grid of 80 cols x 24 rows (the area which is being painted) - into each of these "cells" a letter can be written.
The data (the chars and some attributes like color, charset...) are stored in a 2 dimensional array of record.
Now, the width/height of the grid is defined by the maxwidth/maxheight of the font multiplied by the number of cols and respectively rows.
If you want to resize the area of the image-canvas which is being written to in DispCells() > DispCell(), you'd have to (in theory at least) either
- change the fontsize on the fly or
- change the number or rows/cols (and deal with changing the size of the data array too) or
- only allow resizing with width and height (of the form) at a constant ratio, or
- stretch/compress the whole lot (with deformation of the font)
The first two possibilities would probably prove to be very messy and require rewriting large sections of the code.

If you don't necessarily want the painted area of the image to resize and are only concerned about the partial gray background of the image, then just set the color of scrollbox1 to clBlack...


0
 
LVL 1

Author Comment

by:peterkiers
ID: 17898278
TName, Thank you for the information.

Peter Kiers
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 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