Link in Statusbar bar Delphi 10

Asked

Viewed 68 times

0

I need to put a link in the status bar of the system, clicking on it will open another function that is already ready, a StatusBar has 3 panels and only 3 should open when click. I am using the event OnDrawPanel to try to format the text in link format.

Follows the code:

procedure TfAAA001.StatusBar1DrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect);
begin
  if Panel.Index = 2 then
  begin
    StatusBar1.Canvas.Font.Color := clBlue;
    StatusBar1.Canvas.FillRect(Rect);
    StatusBar1.Canvas.TextOut(Rect.Right, Rect.Top + 1, Panel.Text);
  end;
end;

Thus the StatusBar not starting, someone knows how to solve.

  • You were able to carry out the tests with the answer I proposed?

1 answer

0


The code is correct, but to trigger the event OnDrawPanel needs to set the style property panel as psOwnerDraw.

This can be done either in design or via code.

I think of something in Create do form, something like:

StatusBar1.Panels.Items[2].Style := psOwnerDraw;

Now for the click:

var
  vPosicao: Tpoint;
begin
  vPosicao := ScreenToClient(Mouse.CursorPos);

  if vPosicao.x <= StatusBar1.Panels[0].Width then
    ShowMessage('Clicou no Primeiro')
  else if vPosicao.x <= (StatusBar1.Panels[0].Width + StatusBar1.Panels[1].Width) then
    ShowMessage('Clicou no Segundo')
  else
    ShowMessage('Clicou no Terceiro');
end;
  • I solved it differently but it was with this concept, I used 3 events, ondraw, onclick and onmousemouve ondraw I used a code to format the specific statusbar as a link, leaving blue, and underlined. using a function similar to this one I received the position in the omousemove, that when it was the one I wanted to change the cursor to a type of link. and in onclick was the function to actually open the link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.