Text to be placed on canvas determined by mouse position
Posted on 2002-03-06
At runtime the user will input some text into edit1. Then the user must click a button to embed the text into paintbox1 which then saves as a bitmap to be stored in the db.
The question I ask is how to place the text into the paintbox - based on where the mouse cursor is positioned by the user. (Really Really want something like the textbox found in word with out the frame)
The user could place many diferent lines of text on the same image.
Below is some of the code I am currently messing around with.
procedure TForm1.Button2Click(Sender: TObject);
var X, Y: Integer;
MousePt : TPoint;
MousePt := Point(PaintBox1.ClientRect.Right div 2, PaintBox1.ClientRect.Bottom div 2);
RectWidth := (Edit1.Width div 2);
RectHeight := (Edit1.Height div 2);
MousePt := PaintBox1.ClientToScreen(MousePt);
Mouse.CursorPos := MousePt;
DragRect := Rect(MousePt.X - RectWidth, MousePt.Y - RectHeight, MousePt.X - RectWidth + (RectWidth * 2), MousePt.Y - RectHeight + (RectHeight * 2));
PaintBox1.Cursor := crDrag;
Texting := True
if Texting then //this is set as boolean in public dec
// Paintbox1.Canvas.TextOut(Width div 2, Height div 2, edit1.Text);// This line works but places in the middle of paintbox therefore no good for me//
paintbox1.Cursor := crdefault;
Texting := false;
please please help