Solved

creating text

Posted on 2000-05-30
11
155 Views
Last Modified: 2010-04-04
how to create a text using tlabel created at run time when everytime we clicked a button the text appears on the form and each label can be drag or resize ?
0
Comment
Question by:davelah
[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
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 4

Expert Comment

by:jeurk
ID: 2863369
Euh, sorry, but you need to reformulate your question.
Regards...
0
 
LVL 3

Expert Comment

by:neostudio
ID: 2863448
will you translate your question to english ???
0
 
LVL 6

Expert Comment

by:edey
ID: 2863508
are you looking to be able to dynamicaly create, at runtime, TLabels that you can drag? If so then you could try something like this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, stdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  TDragLabel = class(TLabel)
  private
     isDragging : boolean;
  end;
var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
     with TDragLabel.create(self) do
     begin
          parent := Form1;
          caption := 'Drag Me!';
          onMouseDown := form1.label1MouseDown;
          onMouseUp := form1.label1MouseUp;
          onMouseMove := form1.label1MouseMove;
     end;
end;

procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
     TDraglabel(sender).isDragging := true;
end;

procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
     TDragLabel(sender).isDragging := false;
end;

procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
   pt : TPoint;
begin
     with sender as TDragLabel do
          if isDragging then
          begin
               pt := form1.screenToClient(clientToScreen(point(x,y)));
               left := pt.x;
               top := pt.y;
          end;
end;

end.


Gl
Mike
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:spiffen
ID: 2863514
I guess he wants an example howto create a label on a form in runtime.
Like the formbuilder works.


procedure TForm1.Button1Click(Sender: TObject);
var lbl :TLabel;
begin
  lbl := TLabel.create(self);
  lbl.Font.Size := 10;
  lbl.caption := 'blabla';
  lbl.Left := 50;
  lbl.Top := 50;
  lbl.parent := self;
  lbl.OnClick := doamoveorreziseproc;
end;

But I can't do the whole thing fast.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2863545
Here's my version. It drops a Label anywhere you click on the form and it doesn't need OnMouseDown and OnMouseUp like edey's   :o)



procedure TForm1.FormClick(Sender: TObject);
var p: TPoint;
begin
  GetCursorPos(p);
  p := ScreenToClient(p);
  with TLabel.Create(Self) do
  begin
    Left := p.x;
    Top := p.y;
    Caption := 'Label';
    Parent := Form1;
    OnMouseMove := LabelMouseMove;
  end;
end;

procedure TForm1.LabelMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var p: TPoint;
    l: TLabel;
begin
   if ssLeft in Shift then
   begin
     l := (Sender as TLabel);
     p.x := X;
     p.y := Y;
     p := l.ClientToScreen(p);
     p := ScreenToClient(p);
     l.left := p.x;
     l.Top := p.y;
   end;
end;
0
 

Expert Comment

by:spiffen
ID: 2863731
And add to FormClick:
  OnMouseDown := LabelMouseDown;

Then add a new proc:
procedure TForm1.LabelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   FirstX := X; // Global integers.
   FirstY := Y; //
end;

To make Epsylons suggestion look even nicer. :)

Cheers..
0
 
LVL 6

Expert Comment

by:edey
ID: 2863748
well done eps :)  It's amazing what one can do if they take a little more time to think :).  Actually I used the mouseDown/Up solution 'cause I was thinking or adding the option to resize the label as well (how can you tell I am supposed to working on a drawing/painting app? :).

Gl
Mike

ps. say davelah are we on the right track here?
0
 

Expert Comment

by:spiffen
ID: 2863753
Darn. Forgot to say that you should subtract FirstX and FirstY from the original mousemove x & y values.
But... It might be early alzheimers symptoms.
0
 
LVL 15

Expert Comment

by:simonet
ID: 2865598
Following...
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2865807
Here's a simple way to drag components around at run-time. It only works with Win Controls, so instead of a label you could use a StaticText component.

procedure TForm1.StaticText1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
  SC_DragMove = $F012;
begin
  ReleaseCapture;
  (sender as TWinControl).perform(WM_SysCommand, SC_DragMove, 0);
end;
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 50 total points
ID: 2887166
Here's my version. It drops a Label anywhere you click on the form and it doesn't need OnMouseDown and OnMouseUp like edey's   :o)



procedure TForm1.FormClick(Sender: TObject);
var p: TPoint;
begin
  GetCursorPos(p);
  p := ScreenToClient(p);
  with TLabel.Create(Self) do
  begin
    Left := p.x;
    Top := p.y;
    Caption := 'Label';
    Parent := Form1;
    OnMouseMove := LabelMouseMove;
  end;
end;

procedure TForm1.LabelMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var p: TPoint;
    l: TLabel;
begin
   if ssLeft in Shift then
   begin
     l := (Sender as TLabel);
     p.x := X;
     p.y := Y;
     p := l.ClientToScreen(p);
     p := ScreenToClient(p);
     l.left := p.x;
     l.Top := p.y;
   end;
end;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 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