PDA

View Full Version : My code is adding pixels :(



Jason2gs
08-22-2007, 08:21 PM
Strange title, but it's the most accurate thing I could think of.

I'm making a small program that can convert an image to different things. (Formats, and hex.) I've run into a problem with displaying the image, however.

procedure TForm1.Button1Click(Sender: TObject);
var
PicH, PicW: Integer;
begin
OpenPictureDialog1.Execute;
Form2.Image1.Picture.LoadFromFile(OpenPictureDialo g1.FileName);
Form2.Caption := ExtractFileName(OpenPictureDialog1.FileName);
PicH := Form2.Image1.Picture.Height;
PicW := Form2.Image1.Picture.Width;
Form2.Image1.Height := PicH;
Form2.Image1.Width := PicW;
Form2.ClientHeight := PicH;
Form2.ClientWidth := PicW;
Form2.HorzScrollBar.Visible := False;
Form2.VertScrollBar.Visible := False;
Form2.Visible := True;
end;

It's suppose to show another form that holds the image selected. It works with some images, but with others, it adds about fifteen pixels from the bottom of Image1 to the bottom of the form's window area. (Client area? Not sure what it's called...)

I'm completely stumped. I've tried subtracting fifteen pixels from ClientHeight, but that doesn't work. That just adds those fifteen pixels to ClientWidth, for some reason...

Anyways, I'm hoping you can help me. Tell me what I'm doing wrong :)

-Mike

Edit: Never mind. Fixed :)

Dan Cardin
08-22-2007, 08:34 PM
make ur window's height and width unchangeable?i forgot what its called to do it(but its possible)

Jason2gs
08-22-2007, 08:41 PM
Why would I do that? I want it to adjust both the size of Image1 and Form2 when it loads the picture in. If I made Form2's bounds unchangeable, there's a chance it'll have to scroll.

Edit: Nevermind, thread closed or whatever. You made me want to see what that property was called, and when I was looking, I found the boolean option "AutoSize". It fixed everything for some reason :p

Edit2: Strange. I guess it didn't... Everything is fine now, but AutoSize didn't fix it. I guess I just had to adjust Image1's height a little bit on the main form. Strange...