Solved

How to align the TImage with the main form.

Posted on 2006-11-07
7
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
have you set the form's "OnResize" event to the one above?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Yes.
0
 
LVL 11

Expert Comment

by:calinutz
Comment Utility
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
Comment Utility
>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
Comment Utility
TName, Thank you for the information.

Peter Kiers
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now