不过可以用StaticText代替procedure TForm1.StaticText1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if (Button = mbLeft) then begin ReleaseCapture; SendMessage((Sender as TStaticText).Handle, WM_SYSCOMMAND, SC_MOVE or 2, 0); end; end;
给你个简单的例子unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; StaticText1: TStaticText; procedure StaticText1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StaticText1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if (Button = mbLeft) then begin ReleaseCapture; SendMessage((Sender as TStaticText).Handle, WM_SYSCOMMAND, SC_MOVE or 2, 0); end; end;procedure TForm1.Button1Click(Sender: TObject); var TT: TStaticText; begin TT := TStaticText.Create(Application); TT.Caption := 'Test'; TT.Parent := Form1; TT.OnMouseDown := StaticText1MouseDown; end;end.
消息的话,需要看WM_SETTEXT的Windows SDK帮助An application sends a WM_SETTEXT message to set the text of a window. WM_SETTEXT wParam = 0; // not used; must be zero lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = mbLeft) then
begin
ReleaseCapture;
SendMessage((Sender as TStaticText).Handle, WM_SYSCOMMAND, SC_MOVE or 2, 0);
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
StaticText1: TStaticText;
procedure StaticText1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StaticText1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = mbLeft) then
begin
ReleaseCapture;
SendMessage((Sender as TStaticText).Handle, WM_SYSCOMMAND, SC_MOVE or 2, 0);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
TT: TStaticText;
begin
TT := TStaticText.Create(Application);
TT.Caption := 'Test';
TT.Parent := Form1;
TT.OnMouseDown := StaticText1MouseDown;
end;end.
statictext的caption呢,我是这样用SendMessage(sthandle(stn),WM_SETTEXT,Memo1.Lines.Text,0);可是会报错,对于每个StaticText起个不同的名字,来保存的话要用指针数组吧,有这样的例子不?
wParam = 0; // not used; must be zero
lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string