开发者

Simple gui design problem

开发者 https://www.devze.com 2023-01-21 11:23 出处:网络
I h开发者_C百科ave a really simple problem, but I don\'t find a nice way how I should solve this:

I h开发者_C百科ave a really simple problem, but I don't find a nice way how I should solve this:

I have a TEdit field. When I enter this Edit-Field, I want to show an Panel. When I click on the panel, the panel should hide. When I leave the edit field, the panel also should hide, but I can't use the onExit event of the editField, because this would hide the panel before I can click it. I'm experimenting for a while to solve this, but can't find an elegant way... Any Ideas? thanks!


Well, that is a tricky one. Have you considered hiding the panel with the onEnter event for every control except the panel and the edit field?

In other words, the panel will not hide itself when you exit the edit field and enter the panel but it will hide itself once it has performed its work.

Exiting the edit field and entering any field other than the panel will also cause the panel to hide.

None of that is driven by the edit field onExit, more by the other fields as you enter them. It's convoluted but it may just work. See the table below for conditions and their associated actions:

              onExit   onEnter     panelAction
              -------  -------     -----------
panel         nothing  nothing     hide panel
edit field    nothing  show panel  nothing
all others    nothing  hide panel  nothing


You can use ActiveControl property of the Form at OnClick event of Panel and OnExit event of the EditField


actually you can use the onExit because the panel is not focuseable, so your edit is still focused when you click on the panel (tested with d7).

it's either this or i didn't understand well what you need. if the latest is the case, try rephrasing like gabr suggested earlier ;)

cheers, G


i test your problem. check it out.

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  Panel1.Visible := true;
end;

procedure TForm1.Edit1MouseLeave(Sender: TObject);
begin
  Panel1.Hide;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.TabStop := False;
  Panel1.Visible := False;
end;

procedure TForm1.Panel1Click(Sender: TObject);
begin
 (Sender as TPanel).Visible := false;
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号