Stark
2012-04-29 13:43:29 UTC
I am creating a few buttons at runtime and I wanted to change appearance of
the button the user is hovering over with the mouse. I don't want to use the
font, which I already use for other purposes. I had the idea to surround the
button with a TBevel, which I could make visible when the mouse was over the
button.
The solution doesn't work. It looks like my code does not apply the property
(visible) to the Bevel, but rather to the Button. Here is my code:
I first create the components at Runtime (in the form OnShow):
for i := 0 to 10 do
begin
aButton := TButton.Create(Self);
aBevel := TBevel.Create(Self);
with aButton do
begin
Name := Format('Button%d', [i]);
Parent := Self;
Left := 16;
Top := 40 + i*25;
Width := 145;
Height := 20;
Caption := Format('Button %d', [i]);
OnMouseEnter := AnyBtnMouseEnter;
OnMouseLeave := AnyBtnMouseLeave;
end;
with aBevel do
begin
Parent := Self;
Left := aButton.Left-2;
Top := aButton.Top-2;
Width := aButton.Width+4;
Height := aButton.Height+4;
Shape:= bsFrame;
Style:= bsRaised;
visible:= false;
end;
end;
The following procedures fail their mission to show and hide the bevel when
the mouse is over the button: The OnMouseLeave proc makes the button not
visible !
procedure Tform1.AnyBtnMouseEnter(Sender: TObject);
begin
If Sender is TButton then
Tbevel(Sender).Visible := true;
end;
procedure Tform1.AnyBtnMouseLeave(Sender: TObject);
begin
If Sender is TButton then
Tbevel(Sender).Visible := false;
end;
the button the user is hovering over with the mouse. I don't want to use the
font, which I already use for other purposes. I had the idea to surround the
button with a TBevel, which I could make visible when the mouse was over the
button.
The solution doesn't work. It looks like my code does not apply the property
(visible) to the Bevel, but rather to the Button. Here is my code:
I first create the components at Runtime (in the form OnShow):
for i := 0 to 10 do
begin
aButton := TButton.Create(Self);
aBevel := TBevel.Create(Self);
with aButton do
begin
Name := Format('Button%d', [i]);
Parent := Self;
Left := 16;
Top := 40 + i*25;
Width := 145;
Height := 20;
Caption := Format('Button %d', [i]);
OnMouseEnter := AnyBtnMouseEnter;
OnMouseLeave := AnyBtnMouseLeave;
end;
with aBevel do
begin
Parent := Self;
Left := aButton.Left-2;
Top := aButton.Top-2;
Width := aButton.Width+4;
Height := aButton.Height+4;
Shape:= bsFrame;
Style:= bsRaised;
visible:= false;
end;
end;
The following procedures fail their mission to show and hide the bevel when
the mouse is over the button: The OnMouseLeave proc makes the button not
visible !
procedure Tform1.AnyBtnMouseEnter(Sender: TObject);
begin
If Sender is TButton then
Tbevel(Sender).Visible := true;
end;
procedure Tform1.AnyBtnMouseLeave(Sender: TObject);
begin
If Sender is TButton then
Tbevel(Sender).Visible := false;
end;