Solved

creating text

Posted on 2000-05-30
11
148 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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