焦点问题

xiaoli2200 2003-10-20 11:14:10
我想实现这样一个东东
比如shape控件,我想把鼠标移上去时就变色,移开时恢复,原来我是在MOUSEMOVE中做的,移开时在别的控件写,把它变回来,但有缺陷,因为移到FORM外就不行了,请问有什么好方法,谢谢
...全文
32 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhp97 2003-10-22
  • 打赏
  • 举报
回复
有一个苯办法,你取得该应用程序窗口在屏幕上的坐标,随时与鼠标即时坐标做比较,如果鼠标在窗口之外就恢复颜色啊!!!取屏幕坐标好象有现成函数可用,不必自己写。
zzh54zzh 2003-10-22
  • 打赏
  • 举报
回复
这个方法可能有些笨,不过我测试过了,符合你的要求:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TShape1 =class (TShape)
private
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
end;

var
Form1: TForm1;
Shape1: TShape1;

implementation

{$R *.dfm}

{ TShape1 }

procedure TShape1.CMMouseEnter(var Message: TMessage);
begin
Form1.Timer1.Enabled := True;
Form1.Timer2.Enabled := False;
end;

procedure TShape1.CMMouseLeave(var Message: TMessage);
begin
Form1.Timer1.Enabled := False;
Form1.Timer2.Enabled := True;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Shape1 := TShape1.Create(Form1);
Shape1.Parent := Form1;
Shape1.Align := alClient;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Shape1.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Shape1.Pen.Style <> psSolid then
Shape1.Pen.Style := psSolid;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
if Shape1.Pen.Style <> psClear then
Shape1.Pen.Style := psClear;
end;

end.
zzh54zzh 2003-10-22
  • 打赏
  • 举报
回复
先看看这个
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TShape1 =class (TShape)
private
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
end;

var
Form1: TForm1;
Shape1: TShape1;
implementation

{$R *.dfm}

{ TShape1 }

procedure TShape1.CMMouseEnter(var Message: TMessage);
begin
Form1.Caption := 'Y';
end;

procedure TShape1.CMMouseLeave(var Message: TMessage);
begin
Form1.Caption := 'N';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Shape1 := TShape1.Create(Form1);
Shape1.Parent := Form1;
Shape1.Align := alClient;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Shape1.Free;
end;

end.
gx 2003-10-21
  • 打赏
  • 举报
回复
gz
xiaoli2200 2003-10-21
  • 打赏
  • 举报
回复
意思是这样,怎么样得到光标在某个控件上,或者怎么样得到光标已经离开这个控件
Alanwn 2003-10-21
  • 打赏
  • 举报
回复
用图片试试好不
herofy 2003-10-21
  • 打赏
  • 举报
回复
我只知道用消息

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧