Re: OpenPictureDialog Problems



"Henry Bartlett" <hambar@xxxxxxxxxxxxxxxxxxxxxxxxx> replied tomessage
news:42e6c9f9$1_1@xxxxxxxxxxxxxxxxxxxxxx
>From <cybatech@xxxxxxxxxxxxx

As I suspected, Images were not being painted by tManyShape.

I have managed to fix the problem

In gpShape.pas make the following changes

1. At the top, add the following credit lines:

{Original Author: Garry Prefontaine}
{Modified to fix painting of image: Henry Bartlett July 27 2005}

2. Add gstImage to the TGPShapeType declaration

TGPShapeType = (gstRectangle, gstSquare, gstRoundRect,
gstRoundSquare,
gstEllipse, gstCircle,
gstDiamond, gstStar,gstPolyGon,
gstTriangleLeft,gstTriangleRight,gstTriangleUp,
gstTriangleDown,gstImage);

3. Modify the SetImage method by adding the line
fShape := gstImage;
at the end;

4. In the Paint method, at the end of the last "case FShape of"..
block, add the lines
gstImage:
Draw (0, 0, fImage);

****************************************

Unit1.pas (Your main form unit)
Note: I have kept the default (not meanigful) names

1. Added the line
fCurrentShape: tManyShape;
to the Prvate declarations section

2. Change the MouseDownOnShape method to read

procedure TForm1.MouseDownOnShape(Sender : TObject;
Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
if Sender is TManyShape then begin
fCurrentShape := TManyShape(Sender);
if ssRight in Shift then
fCurrentShape.Tag := RIGHT_BUTTON_DOWN
else
begin
fCurrentShape.Tag := RIGHT_BUTTON_UP;
if ssLeft in Shift then begin
FMouseDown.x := X;
FMouseDown.y := Y;
FMovingShape := TRUE;
end;
end;
end;
end;

Since we need to set fCurrentShape, using this variable instead of the
several (Sender as tManyShape) items, makes the code more readable.

3. Add the line
fCurrentShape := NewShape;
to the end of each of your SpeedButton event handlers.

4. Change the Button1Click/BitBtn1Click event handler to read

procedure TForm1.Button1Click(Sender: TObject);
var OpenPicDlg : TOpenPictureDialog;
Bitmap: TBitmap;
begin
if Assigned (fCurrentShape) then begin
BitMap := tBitMap.Create;
OpenPicDlg := TOpenPictureDialog.Create(Self);
// not having TOpenPictureDialog, I used tOpenDialog
// plus a couple of extra lines
Try
if OpenPicDlg.Execute then begin
bitmap.LoadFromFile(OpenPicDlg.FileName);
fCurrentShape.Width:= BitmapWidth;
fCurrentShape.Height := Bitmap.Height;
fCurrentShape.Image := Bitmap;
// assigning Bitmap to Image copies the contents of the bitmap so
// it will not be used again and needs to be freed.
end;
finally
OpenPicDlg.Free;
Bitmap.Free;
end;
end
else
MessageDlg ('No shape selected', mtError, [mbOK], 0);
end;

Henry Bartlett
Delphi Links Page:
( http://www.hotkey.net.au/~hambar/habit/delflink.htm )



.


Quantcast