R – How Do I Add A TLabel To The Menu Bar in Delphi

delphilabeluser interfacevcl

I use Beyond Compare (a great program), and was very impressed when it displayed a "New Version Available" label on its Menu Bar. I clicked on it, up popped an install new version box, it installed, the program restarted itself and there was the new version and no more label.

I thought that was a great feature. The label is there prominently on the menu bar where the user can't miss it. I've already got the update procedure, so all I had to do was add the label. That should be easy.

Here's the label where I want it:
The Label Where I Want It
(source: beholdgenealogy.com)

… Wrong. I couldn't figure out how to add a label there. The menu bar and the control area above it appear to be hands-off area for visual components. I couldn't place one there.

But I know it can be done, because Beyond Compare is a Delphi program.

Can anyone tell me what I have to do to put a TLabel in my Menu Bar or at least make it appear to be over the Menu Bar in the correct position?

For reference, I use Delphi 2009.


Conclusion: Christopher seems to have correctly figured out what the Beyond Compare people did. I've decided to implement the menu item, but without the customization of his "owner draw" solution. So I don't get the blue bold underline hyperlink look, but I also don't lose all the automatic things (like the Vista styling) that owner draw skips.

To space the menu item over to the right, I've added an item after the "Help" that has the caption " " and is disabled.

Thanks, Christopher. I was stuck thinking it must be a Label, but you saw around that.

Best Answer

Are you sure it's a label?

I haven't used the program, but it could just be a menu item, set to 'owner draw' and painted to look like a link?

http://sirmonkeys.com/images/updatelink.png
(done in Delphi 7)

procedure TForm1.MYITem1DrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
begin
  acanvas.Font.Style := [fsUnderline,fsbold];
  acanvas.Font.color := clblue;
  acanvas.Brush.Style := bsClear;
  acanvas.TextOut(arect.left+1,arect.top+1,'Link to Update...');
end;

procedure TForm1.MYITem1MeasureItem(Sender: TObject; ACanvas: TCanvas;
  var Width, Height: Integer);
begin
  width := 100;
end;

and then either a have an ImageList assigned to MainMenu1.Images or set MainMenu1.OwnerDraw to true.

Related Topic