Delphi change color of main menu

Rudi

I am creating my own OnAdvancedDrawItem to change the color of the MainMenu. It works well but I get an annoying white line at the bottom.

line under main menu

It disappears when running the mouse over the menu but comes back when another application is selected. How can I get rid of it?

Here is my basic code for the background coloring.

unit MenMain;

interface

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, Menus, ImgList, StdCtrls;

type
  TForm1 = class(TForm)
  MainMenu1: TMainMenu;
  File2: TMenuItem;
  Edit1: TMenuItem;
  Window1: TMenuItem;
  procedure Window1AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
private

public

end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Window1AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;  ARect: TRect; State: TOwnerDrawState);
begin
  with TMenuItem(Sender) do
  begin
    with ACanvas do
    begin
      Brush.Color := clMoneyGreen;
      Inc(ARect.Bottom,1);
      FillRect(ARect);
      Font.Color := clBlue;
      DrawText(ACanvas.Handle, PChar(Caption),Length(Caption),ARect,          DT_SINGLELINE or DT_VCENTER);
    end;
  end;
end;

end.
Sertac Akyuz

The ARect parameter of the OnAdvancedDrawItem event handler is the rcItem of the DRAWITEMSTRUCT that's passed to the WM_DRAWITEM message. The documentation has this to say about the rectangle:

A rectangle that defines the boundaries of the control to be drawn. This rectangle is in the device context specified by the hDC member. The system automatically clips anything that the owner window draws in the device context for combo boxes, list boxes, and buttons, but does not clip menu items. When drawing menu items, the owner window must not draw outside the boundaries of the rectangle defined by the rcItem member.

So although the device context is not clipped to the rectangle, you're responsible for not drawing outside of it. That happens when you execute Inc(ARect.Bottom,1); before filling the rectangle.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delphi change color of main menu

From Dev

¿Change text color main menu android?

From Dev

Couldn't change the border color for each item on main menu

From Dev

Change the color of menu icon

From Dev

Cant change the color of a TPanel in delphi

From Dev

delphi change canvas pixel color

From Dev

Is a themed Main Menu with icons possible in Delphi?

From Dev

Change icon on MATE main menu

From Dev

menu background change color on scroll

From Dev

OpenCart 1.5.6.4, change the menu color

From Dev

How to change the color of menu text?

From Dev

OpenCart 1.5.6.4, change the menu color

From Dev

Change the text color of the popup menu

From Dev

How to change the menu background color

From Dev

Change the color of the text in Toolbar menu

From Dev

Change color of menu font on ActionBar

From Dev

Change color of default navigation menu

From Dev

color change dropdown menu javascript

From Dev

Change Face Color From main color in xcode

From Dev

Delphi Change main form while application is running

From Dev

How to change cell color in a TCalendar Component in Delphi?

From Dev

Delphi Change Metropolis UI font color

From Dev

Change position to the default main menu of a theme

From Dev

How to change main menu icons in Android app

From Dev

Main Window title bar color change in wpf

From Dev

How to change Options menu dots color?

From Java

Change the color of a checked menu item in a navigation drawer

From Dev

Change default actionbar popup menu background color

From Dev

How to change Menu indicator color in activity ToolBar