Edit1にあるときだけButton1のEnabledをTrueにしたいのですが、どこで設定すればいいでしょうか。
Edit1のOnEntreでButton1のEnabledをTrueにしても、他のところにフォーカスを移動させた時にボタンを押すことができました。
何かほかにやり方があるのでしょうか。
OnExitでButton1のEnabledをFalseにすれば?
単純に Exit で False すると Button1 を押す直前に Exit が実行されて
Enabled := False になってしまうのでボタンが押せなくなってしまいます。
なので
procedure TForm1.Button1Exit(Sender: TObject);
begin
if ActiveControl <> Button1 then
begin
Button1.Enabled := False;
end
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
if ActiveControl <> Button1 then
begin
Button1.Enabled := False;
end
end;
のようにしてください
SpeedButtonとの併用はだめですか?
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if ActiveControl = Edit1 then
showmessage('Edit1');
end;
ツイート | ![]() |