gpt4 book ai didi

Delphi改变主菜单颜色

转载 作者:行者123 更新时间:2023-12-03 15:48:15 28 4
gpt4 key购买 nike

我正在创建自己的 OnAdvancedDrawItem 来更改 MainMenu 的颜色。它运作良好,但我在底部看到一条烦人的白线。

line under main menu

当鼠标悬停在菜单上时它会消失,但当选择另一个应用程序时它会回来。我怎样才能摆脱它?

这是我的背景着色的基本代码。

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.

最佳答案

ARect OnAdvancedDrawItem的参数事件处理程序是 rcItem DRAWITEMSTRUCT的已传递给 WM_DRAWITEM信息。 documentation关于矩形有这样的说法:

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.

因此,尽管设备上下文没有被剪切到矩形,但您有责任不在其外部进行绘制。当您执行 Inc(ARect.Bottom,1); 时就会发生这种情况在填充矩形之前。

关于Delphi改变主菜单颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342072/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com