Solved

Text to be placed on canvas determined by mouse position

Posted on 2002-03-06
5
224 Views
Last Modified: 2010-04-04
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;
begin
     Application.ProcessMessages;
     Sleep(200);
     UnDoBmp.Assign(PB5Bmp);
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;
     PaintBox1.Canvas.Rectangle(DragRect);
     Texting := True

end;



On paintbox1click

if Texting then //this is set as boolean in public dec
     begin
          begin
          PaintBox1.Canvas.Rectangle(DragRect);
         // 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.Canvas.TextOut(DragRect.Left, DragRect.Top,edit1.text);
          end;
          paintbox1.Cursor := crdefault;
          Texting := false;
  end;


please please help

V
0
Comment
Question by:Vanessa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
zebada earned 100 total points
ID: 6845531
I have written a small paint program - it does not have the text feature but if you add the following lines of code to the TMDIChild.doTextDown method it will do what you want.

You can download the source code here:
http://www.blacky.co.nz/free/paint.zip

Change this method in the "Child" unit.

procedure TMDIChild.doTextDown(X,Y: integer);
var
  t: string;
begin
  t := InputBox('Enter text to be displayed','Text:','');
  if ( t='' ) then
    exit;
  img.Picture.Bitmap.Canvas.TextOut(X,Y,t);
end;

0
 
LVL 34

Expert Comment

by:Slick812
ID: 6854148
hello, you use the OnClick event of the paint box, but this does NOT give you the mouse position, you can use the MouseDown or MouseUp event to get the cursor position


procedure TForm1.PaintBox3MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Texting then
  begin
  PaintBox1.Canvas.Font.Color := clRed;
  Paintbox1.Canvas.TextOut(X, Y,edit1.text);
  Texting := False;
  end;
end;

Does this help? Let me know if you need more.
0
 

Author Comment

by:Vanessa
ID: 6858189
Slick812 and Zebada
Both of you have been very helpful. THANKS.
One more question -  the text appears on the canvas with a grey background 90% of the time.  Is there something I can do to stop this altogether ?

V

0
 
LVL 6

Expert Comment

by:zebada
ID: 6858207
Canvas.Brush.Style := bsClear;
Prior to TextOut().

0
 

Author Comment

by:Vanessa
ID: 6858220
Thanks Zebada

One question, the text on the canvas has a grey background 90% of the time. Can you suggest a solution.

V
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month4 days, 9 hours left to enroll

636 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