?
Solved

How to align the TImage with the main form.

Posted on 2006-11-07
7
Medium Priority
?
302 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
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 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

743 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