您好,请教一个问题,谢谢(50分)

  • 主题发起人 主题发起人 wjlsnet
  • 开始时间 开始时间
W

wjlsnet

Unregistered / Unconfirmed
GUEST, unregistred user!
您好,我想实现如下效果 :

Form 上有 Edit1 -- Edit5 5 个 Edit , 当鼠标在某个Edit的区域内时,Form.Caption 为
该 Edit.Text ;

要求 : 不用 wm_nchittest 消息 ,用其他方式

谢谢
 
在每个edit控件的onmousemove事件写
label1.caption := 相应edit.text
 
//其他Edit的OnMouseMove设为此事件即可
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Caption := (Sender as TEdit).Text
end;
 
谢谢,试过了,那样作相应很慢很慢

望继续指导
 
edit在得到焦点时才改变form.caption比较好吧.
如果焦点在edit1,而数标在edit2,这时form.caption显示edit2
用户输入时却还在edit1.恐怕不太好吧.
 
当然了:) ,我想得到的效果也是 : 鼠标在其区域或者 Focused 时, Form.Caption 为 其
Text

谢谢,望指导
 
增加一个鼠标移入控件或者移出控件的消息即可啦!
 
当然,上面的方法可以。
还有很多方法,这不是一个多难的问题,我想你自己试一试就可一得到结果了。

什么事都要自己亲自去try,你回有更多的收获的。
 
可是现在该使用哪个消息我不知道 ,或者哪儿有相关资料 ?

谢谢
 
DELPHI预定义的两个消息:
CM_MOUSEENTER 和 CM_MOUSELEAVE。 Below 已经提供了部分使用它们的代码,
我试了,对TSPEEDBUTTON有效,相信对其它也有效。
unit SomeForm;
interface
type
TSomeForm = class(TForm)
private
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
end;
implementation
procedure TSomeForm.CMMouseEnter(var Msg: TMessage);
var
anObject : TObject;
begin
{ anObject is the control over which the mouse is right now }

anObject := TObject(Msg.lParam);
if anObject nil then begin
{ First, you must find WHICH is the control under the mouse cursor, }
{ then, determine what action to do, etc... }
end;
end;
procedure TSomeForm.CMMouseLeave(var Msg: TMessage);
begin
{ anObject is the control which the mouse has just gone out of }
anObject := TObject(Msg.lParam);
if anObject nil then begin
{ First, you must find WHICH is the control }
{ the mouse cursor has just left, }
{ then, determine what action to do, etc... }
end;
end;
end.
 
谢谢您

人在昆明 :

能不能简单的写一个例子 ? 您给的代码的好多地方我还不会写...

谢谢您
 
新建一个form 放上两个 按钮 button1,button2。

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
private
procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
public

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CMMouseEnter(var Msg: TMessage);
var
anObject: TObject;
begin
anObject := TObject(Msg.lParam);
if ((anObject <> nil) and (anObject = Button1)) then
begin
ShowMessage('鼠标进入button1');
end;
end;

procedure TForm1.CMMouseLeave(var Msg: TMessage);
var
anObject: TObject;
begin
anObject := TObject(Msg.lParam);
if ((anObject <> nil) and (anObject = Button2)) then
begin
ShowMessage('鼠标离开button2');
end;
end;

end.

 
谢谢您 ,还想请教您,关于这些系统消息的知识应该怎样学习 ? 从哪里入手 ?

谢谢您
 
哈哈,俺也是菜鸟,你问这个俺就不知道啦,学习的问题俺不知道,
俺只知道吃饭、睡觉、花钱,这样的问题还是问问 其他富翁吧,
我可是穷光蛋,看看我的介绍,菜鸟一只呀!
 
后退
顶部