views:

428

answers:

2

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

... 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.

+12  A: 

are you sure its a label?

i havent used the program,

but it could just be a menu item, set to 'owner draw' and painted to look like a link?


(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 = true

Christopher Chase
That might be possible. I'll try that.
lkessler
lkessler
Accelerators appear automatically when you act like you're going to use the keyboard to activate the menu, which means pushing the Alt key. Christopher probably pressed Alt+PrntScr to make the image, so the accelerator indicators appeared. This has been the default Windows behavior for about 10 years now. If you want them visible all the time, adjust your display settings in the OS control panel.
Rob Kennedy
Christopher solution is a replica so exact that even reproduces the bug(?)feature(?) of erasing the menu background on the menu item display area.
PA
@lkessler: You can't get the accelerators back unless the VCL bug which kills them is fixed (see your own question http://stackoverflow.com/questions/280247/menu-accelerator-keys-not-showing-up-delphi-2009).
mghie
PA: Actually, for the picture of my question, I cut and pasted the "New Version Available" onto the image of my program, which is why the background behind the words appears white.
lkessler
No this is a bit different because that bug only applied to submenus. But in this case, the accelerators were no longer on the main menu items when I went to OwnerDraw. None-the-less I decided not to use the OwnerDraw technique (see my conclusion on the question)
lkessler
@lkessler: It's not really a VCL bug, more of a failure to work around a Windows problem. I have edited my answer to your question with code to work around the issue. This should take care of this one as well, if you go with an owner drawn menu item.
mghie
+1  A: 

Beyond Compare's implementation is actually a TLabel. We use Toolbar 2000 for our menus and toolbars, so embedding a control on the menu directly is supported (with a correct background), and it has the advantage that it supports right-justified menu items.

Craig Peterson
Thanks, Craig. So it actually is a label then. You technically have the correct answer (using Toolbar 2000), but I've already implemented it as an uncolored menu item, so I'll leave the accepted answer with Christopher. Didn't know you were here at StackOverflow. Love your Beyond Compare. I use it for comparing my versions, updating my website, and doing my backups.
lkessler