Solved

creating text

Posted on 2000-05-30
11
145 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now