Solved

creating text

Posted on 2000-05-30
11
149 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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