BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

jpg/TImage/Panel alignment

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Phil Rockwell
Guest





PostPosted: Wed Apr 11, 2007 8:52 pm    Post subject: jpg/TImage/Panel alignment Reply with quote



I'm developing an engineering app in Delphi 7 for analyzing bolts. I'm
using a page control with several tabs. In one area of the program, the
user will select the type of bolt head. All the bolt heads are shown in
a group box. For each type of bolt head, there is a radio button with
verbal description, and (I hope), a small image of the corresponding
type of bolt head.

So far, I have created images by doing a screen grab of a SolidWorks
solid model using SnagIt to generate a jpg file. I place a small panel
on the form near the appropriate radio button, place a TImage on the
panel, and load the jpg into the TImage. After spending about 45
minutes tweaking the panel and the TImage, I was finally able to get an
arrangement that looked satisfactory. I worked on a second image,
taking great pains to make the second jpg, panel and TImage exactly the
same pixel dimensions as the first one, and ended up with something that
looked like it would need another 45 minutes of tweaking.

I need to create about 20 different such images, and would prefer not to
have to spend so much time and effort on each one. It seems like there
should be a way to get the panel, TImage and jpg to automatically align
with each other nicely, but I was not able to accomplish this. I tried
many combinations of Autosize, Proportion, Stretch etc.

I'm completely open to using other components - just want to have
something that "frames" the image.

Any suggestions?
Back to top
Peter Below (TeamB)
Guest





PostPosted: Thu Apr 12, 2007 12:41 am    Post subject: Re: jpg/TImage/Panel alignment Reply with quote



Phil Rockwell wrote:

Quote:
I'm developing an engineering app in Delphi 7 for analyzing bolts.
I'm using a page control with several tabs. In one area of the
program, the user will select the type of bolt head. All the bolt
heads are shown in a group box. For each type of bolt head, there is
a radio button with verbal description, and (I hope), a small image
of the corresponding type of bolt head.

So far, I have created images by doing a screen grab of a SolidWorks
solid model using SnagIt to generate a jpg file. I place a small
panel on the form near the appropriate radio button, place a TImage
on the panel, and load the jpg into the TImage. After spending about
45 minutes tweaking the panel and the TImage, I was finally able to
get an arrangement that looked satisfactory. I worked on a second
image, taking great pains to make the second jpg, panel and TImage
exactly the same pixel dimensions as the first one, and ended up with
something that looked like it would need another 45 minutes of
tweaking.

I need to create about 20 different such images, and would prefer not
to have to spend so much time and effort on each one. It seems like
there should be a way to get the panel, TImage and jpg to
automatically align with each other nicely, but I was not able to
accomplish this. I tried many combinations of Autosize, Proportion,
Stretch etc.

I'm completely open to using other components - just want to have
something that "frames" the image.

Any suggestions?

You are trying to do too much using the designer and forget that you
can do anything you can do in the designer in code as well, and
sometimes that is the easier option.

Start by setting the Tag property of your radiobuttons to a number that
uniquely identifies them, say 1 to 20. Then create your jpeg images and
also name them with the corresponding number, say bolthead01.jpg to
bolthead20.jpg. Create a text file in your project directory, name it
boltheads.rc. In it you place lines like

BOLT01 RCDATA "bolthead01.jpg"
BOLT02 RCDATA "bolthead02.jpg"
....
BOLT20 RCDATA "bolthead20.jpg"

This assumes that the JPG files are in the same folder as the RC file.
You can use relative or absolute pathes for the files, if you like.

Use the Project->Add to project menu to add this file to your project.
If you build the project now the IDE will compile the RC file to a RES
file and add that to the executable. You now have a way to get at those
images from your code without having to ship the individual JPG files.

Now go to your forms code and add a handler for the OnCreate event, if
you don't have one already. Add a call

CreateBoltheadImages;

at the end of the handler.

Add a new (private) method with this name, there you will add the code
to create the controls in question. The method would go something like
this:

procedure TMyForm.CreateBoltheadImages;
var
Container: TwinControl;
I: Integer;
begin
// We assume that all radiobuttons have the same parent!
Container := BoltRadiobutton1.Parent;
for I:= 0 to Container.ControlCount-1 do
if (Container.Controls[I] is TRadiobutton) and
(Container.Controls[I].Tag > 0) then
CreateBoltheadImage(TRadiobutton(Container.Controls[I]));
end;

We need another method that will handle the image for a single
radiobutton now:

procedure TMyForm.CreateBoltheadImage(aRadiobutton: TRadiobutton);
const
JpgWidth = 16; // pick a value
JpgHeight = 16; // pick another value
Spacing = 4; // space between image and radiobutton
var
Panel: TPanel;
Image: TImage;
Jpg: TJepgImage;
RS: TResourceStream;
begin
RS:= TResourceStream.Create( hInstance,
Format('BOLT%2.2d',[aRadiobutton.Tag]), RT_RCDATA);
try
Jpg := TJpegImage.Create;
try
Jpg.LoadFromStream(RS);
Panel:= TPanel.Create(Self);
Panel.Parent := aRadiobutton.Parent;
Panel.SetBounds(
aRadiobutton.Left - JpgWidth - Spacing - 4,
aRadiobutton.Top - (JpgHeight - aRadiobutton.Height) div 2 - 2,
JpgWidth + 4, JpgHeight + 4);
Image := TImage.Create(self);
Image.Parent := Panel;
Image.SetBounds(2,2,JpgWidth, JpgHeight);
Image.Picture.Graphic := Jpg; // makes a copy of Jpg!
Panel.Show;
Image.Show;
finally
Jpg.Free;
end;
finally
RS.Free;
end;
end;

I hope you get the picture <g>. This code has been typed directly into
the newsgroup editor, so it may not even compile as is.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.