Solved

creating text

Posted on 2000-05-30
11
142 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

17 Experts available now in Live!

Get 1:1 Help Now