如何实现鼠标移动到一个button上就改变button.caption,移开后恢复原来的caption

jzbmoc 2003-05-07 04:22:52
如题
...全文
93 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ad311500 2003-05-08
  • 打赏
  • 举报
回复
把bglong(阿笨)和BOZ的方法加起来使用是最好的方法
yzf111 2003-05-08
  • 打赏
  • 举报
回复
虽然用PANEL把BUTTON包起来了,但是如果button的LEFT=0时,MOUSE从BUTTON左边移出去时可能并不会触发PANEL的MOUSEOVER事件,这样会没问题吗,望各位大侠考虑一下。
jzbmoc 2003-05-07
  • 打赏
  • 举报
回复
right,用panel把button包起来,然后按照boz(波)兄的做法(这厮什么名字·!#¥·%),问题解决了。
gytyl 2003-05-07
  • 打赏
  • 举报
回复
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
button1.caption:='新值'
end;
//其他button周围的
procedure TForm1.xxxxMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
button1.caption:='旧值'
end;


应该可以实现的。
bglong 2003-05-07
  • 打赏
  • 举报
回复
把button用一个其他的控件(比如panel)包起来就好了!!
ad311500 2003-05-07
  • 打赏
  • 举报
回复
同意BOZ
fhuibo 2003-05-07
  • 打赏
  • 举报
回复
同意boz
gexinmin2008 2003-05-07
  • 打赏
  • 举报
回复
看看事件触发顺序你就明白了.
yzf111 2003-05-07
  • 打赏
  • 举报
回复
to boz,难道周围所有的控件都要写上button1.caption:='旧值'吗,这样似乎不是办法吧

anaikh 2003-05-07
  • 打赏
  • 举报
回复
I agree with boz!
yhq2002 2003-05-07
  • 打赏
  • 举报
回复
我想是用ONenter和 onexit事件吧
boz 2003-05-07
  • 打赏
  • 举报
回复
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
button1.caption:='新值'
end;
//其他button周围的
procedure TForm1.xxxxMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
button1.caption:='旧值'
end;

用delphi做的计算器。unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Scr: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; Button9: TButton; Button10: TButton; Button11: TButton; Button12: TButton; Button13: TButton; Button14: TButton; Button15: TButton; Button16: TButton; Button17: TButton; Button18: TButton; Button19: TButton; Button20: TButton; procedure Button1Click(Sender: TObject); procedure Button12Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button13Click(Sender: TObject); procedure Button20Click(Sender: TObject); procedure Button19Click(Sender: TObject); procedure Button18Click(Sender: TObject); private { Private declarations } pnt,er,fb:boolean; fstnm:Extended; fbcaption:string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var temp:string; begin if er then exit; if pnt then scr.Caption:=scr.Caption+(sender as Tbutton).Caption else if (scr.Caption='0.') or fb then begin scr.Caption:=(sender as Tbutton).caption+'.'; fb:=false; end else begin temp:=scr.Caption; insert((sender as Tbutton).Caption,temp,length(temp)); scr.Caption:=temp; end; end; procedure TForm1.Button12Click(Sender: TObject); var temp:string; begin if er then exit; if scr.Caption<>'0.' then if pos('-',scr.Caption)>0 then begin temp:=scr.Caption; delete(temp,1,1); scr.Caption:=temp; end else scr.Caption:='-'+scr.Caption; end; procedure TForm1.FormCreate(Sender: TObject); begin pnt:=false; fstnm:=0; fb:=false; fbcaption:=''; er:=false; end; procedure TForm1.Button11Click(Sender: TObject); begin if er then exit; pnt:=true; end; procedure TForm1.Button13Click(Sender: TObject); begin if er then exit; if not fb then button20click(nil); if er then exit; fstnm:=strtofloat(scr.Caption); fbcaption:=(sender as Tbutton).Caption; fb:=true; pnt:=false; end; procedure TForm1.Button20Click(Sender: TObject); begin if er then exit; if fbcaption='+' then begin scr.Caption:=floattostr(strtofloat(scr.Caption)+fstnm); end; if fbcaption='-' then begin scr.Caption:=floattostr(fstnm-strtofloat(scr.Caption)); end; if fbcaption='*' then begin scr.Caption:=floattostr(strtofloat(scr.Caption)*fstnm); end; if fbcaption='/' then begin if scr.Caption<>'0.' then scr.Caption:=floattostr(fstnm/strtofloat(scr.Caption)) else begin scr.Caption:='zero divid error!'; er:=true; end; end; if pos('.',scr.caption)=0 then scr.Caption:=scr.Caption+'.'; fb:=true; pnt:=false; fbcaption:=''; end; procedure TForm1.Button19Click(Sender: TObject); begin pnt:=false; fstnm:=0; fb:=false; fbcaption:=''; er:=false; scr.Caption:='0.'; end; procedure TForm1.Button18Click(Sender: TObject); begin if er then exit; scr.Caption:='0.'; end; end.

5,388

社区成员

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

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