5

I use a Toolbar as a MainMenu!

I embed a MainMenu into a ToolBar. But the text of the MainMenu (button's captions) is not in the center of ToolButtons.

I have: enter image description here

I need: enter image description here

I create a ToolBar, 4 ToolButtons and assign each menu for each button. Or I assign a MainMenu in "Menu" of a ToolBar. When I create a ToolBotton then it's caption is already at the bottom. Does nobody have the same?

After all these I will embed the ToolBar as the MainMenu into a CoolBar. Finally, I will have the same as in Windows Firewall.

Are there alternatives to have the same effect like the CoolBar of Windows Firewall (with the MainMenu + a break-line + ToolButtons of the ToolBar)? I use Delphi 2010.

How to do this? How to use properly a MainMenu in a ToolBar? Thanks!

P.S. Another example and it is not from Windows: enter image description here

and how to copy the last example...

maxfax
  • 4,281
  • 12
  • 74
  • 120
  • You need to tell us what you have done. The window menu of a `TMainMenu` *cannot* even be positioned inside a `TToolBar`, so you are obviously doing something else... Are you perhaps using a `TToolBar` and regular `TToolButton` buttons as 'menus'? – Andreas Rejbrand Jul 02 '11 at 22:51
  • @Andreas, simply set the 'MenuItem' of a TToolButton to one of parent items of a TMainMenu. – Sertac Akyuz Jul 02 '11 at 22:59
  • @Sertac: Well, of course you can assign drop-down menus to tool buttons, but then you get two menu bars, because you do get one from the `TMainMenu` the OP is talking about... – Andreas Rejbrand Jul 02 '11 at 23:02
  • @Andreas - As I understand it, maxfax is not setting the 'Menu' of the form to 'MainMenu1', and is using the toolbar as a main menu by setting 'MenuItem' of buttons to items of the 'MainMenu1'. I may be wrong of course.. – Sertac Akyuz Jul 02 '11 at 23:04
  • @Sertac: Still, if you set the `Menu` property of the form you do get a result very similar to the 'I need' screenshot. – Andreas Rejbrand Jul 02 '11 at 23:05
  • @Andreas - Indeed! Maybe he wants to be able to position the menu bar to some place other than the top of the window, who knows? – Sertac Akyuz Jul 02 '11 at 23:07
  • I want the same as on the pictures. The ToolBar as the MainMenu and on the top of the window. Like in Windows Firewall. After all these I will embed the ToolBar as the MainMenu into a CoolBar. Finally I will have the same as in Windows Firewall. – maxfax Jul 02 '11 at 23:12
  • @maxfax: So, if I understand you correctly, it is not *enough* to have it look like the menu in the Windows Firewall GUI. Instead, you want it to look like this *and* the menu bar *has* to be a `TToolBar`? – Andreas Rejbrand Jul 02 '11 at 23:14
  • If I am not wrong Windows Firewall GUI uses CoolBar. And I use it too. – maxfax Jul 02 '11 at 23:16
  • I also have to object against the `TToolBar` approach, because the toolbar buttons do not behave when you click them (that is, when you drop down the menu associated with the button). At least this is the case in Delphi 2009. – Andreas Rejbrand Jul 02 '11 at 23:17
  • @maxfax: But why in the world do you write `ToolBar` and not `CoolBar` in your question, then?! OK, I think I get it. The `TCoolBar` has a `TCoolBand` with a `TToolBar` as its `Control`. So your issue has actually nothing to do in particular with the `TCoolBar`. You are just annoyed by the way a `TToolBar` draws a menu (no matter if the tool bar is located in a cool band or not). – Andreas Rejbrand Jul 02 '11 at 23:17
  • I did not know that it was a big difference. I thought if I would do it will the ToolBar then I would embed that ToolBar into the CoolBar. The ToolBar as the MainMenu -> the CoolBar = happiness! – maxfax Jul 02 '11 at 23:22
  • @maxfax: Yes, you are completely right. I am sorry, I didn't see that right away. – Andreas Rejbrand Jul 02 '11 at 23:23
  • If I may ask, why is it important for you to use a `TToolBar` as your menu bar? I am asking this because, at least in Delphi 2009, a `TToolBar` used as a menu bar doesn't behave right when you click the buttons (that is, when you drop down the menus). – Andreas Rejbrand Jul 02 '11 at 23:25
  • Anyhow, in Delphi 2009, I cannot reproduce this additional padding above the labels. There might be a pixel or so too much, but not as much as on your screenshot. http://privat.rejbrand.se/ToolbarAsMenuPaddingTop.png. Anyhow, if you want your app to look good and/or like the Windows Firewall GUI, I don't think it is a good idea to use a `TToolBar` as menu bar. – Andreas Rejbrand Jul 02 '11 at 23:38
  • guys, I do not care how to do it and what alternatives to use but I want an effect like in Windows Firewall :) Like the Coolbar with the MainMenu + break-line + other ToolButtons. – maxfax Jul 02 '11 at 23:39
  • @maxfax: Now I finally understand what you mean! – Andreas Rejbrand Jul 02 '11 at 23:39
  • +1 because this is a good question when you finally get it. – Andreas Rejbrand Jul 02 '11 at 23:52
  • Thanks! It is good! And a right answer or an advice is so needed :) – maxfax Jul 02 '11 at 23:56
  • There's not only the eccentricity about the TToolBar/TCoolBar solution that makes it different from WF's menu bar, but also the absent 'glare' or 'convexity' effect. WF may well use a very different component altogether. – Andriy M Jul 03 '11 at 00:14
  • @Andriy - According to Spy++, they're 'ToolbarWindow32's alright. They might be using custom drawing of course.. – Sertac Akyuz Jul 03 '11 at 00:34
  • @Sertac: Indeed, and the visual effect might be the TCoolBar/TWhateverBar's background. (Don't know why I didn't think of that before.) – Andriy M Jul 03 '11 at 00:37
  • Here is a topic on MSDN that should get you in the right direction: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775450 – pcunite Nov 30 '11 at 22:49

1 Answers1

2

Here's what might help:

  1. Drop an empty TImageList on the form.

  2. Assign it to the ToolBar.

  3. Set ToolBar.List to True.

  4. Adjust ImageList.Height to your taste.

This will result in the buttons adjusting their heights to the ImageList.Height value and their captions getting centred vertically.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • But it is a space after a caption...It is better than nothing :) – maxfax Jul 03 '11 at 03:05
  • There was no space in my case. (I had `ToolBar.Menu` set to the `TMainMenu` instance.) In your case you might try playing with `ImageList.Width`. – Andriy M Jul 03 '11 at 03:11
  • I did all your steps + ImageList.Width=1. It did not help. But it is not a big deal :) I use Dellphi 2010. – maxfax Jul 03 '11 at 03:33