Solved

How to align the TImage with the main form.

Posted on 2006-11-07
7
284 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
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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 177
Printing problem 2 109
Intraweb download file link ? 1 166
creating threads in delphi 1 155
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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