Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to align the TImage with the main form.

Posted on 2006-11-07
7
Medium Priority
?
313 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

597 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