Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Text to be placed on canvas determined by mouse position

Posted on 2002-03-06
5
Medium Priority
?
227 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

721 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