XPMenu是一個不錯的程序界面效果控件,但它也存在不少不足之處。我最近又對它作了一點修改。
原因是我在程序裡有一個ToolButton,其Style=tbsButton,當Down=True時,XPMenu繪制的效果效果跟Down=False時一樣,也就是說根本看不出它是按下的。當把Style改為tbsCheck後,卻能顯示效果,但是底色很深。
這個按鈕來我是用來表示某個面板是否可以顯示的,我希望它像OfficeXP的工具按鈕那樣,當工具條顯示時,在按鈕上畫個邊框即可,而不是以很深的底色顯示。
XPMenu繪制工具欄按鈕是由TXPMenu.ToolBarDrawButton函數完成,原型為如下:
procedure TXPMenu.ToolBarDrawButton(Sender: TToolBar; Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean); 在函數內由以下代碼決定按鈕是否顯示邊框,以及用什麼顏色作底色:
if (cdsHot in State) then
begin
if (cdsChecked in State) or (Button.Down) or (cdsSelected in State) then
ACanvas.Brush.Color := FCheckedAreaSelectColor
else
ACanvas.brush.color := FBSelectColor;
HasBorder := true;
HasBkg := true;
end;
if ((cdsChecked in State) and not (cdsHot in State)) then
begin
ACanvas.Brush.Color := FCheckedAreaColor;
HasBorder := true;
HasBkg := true;
end;
if (cdsIndeterminate in State) and not (cdsHot in State) then
begin
ACanvas.Brush.Color := FBSelectColor;
HasBkg := true;
end;
它忽略掉了非cdsHot、非cdsChecked狀態下按鈕的Down=True的情況的處理。因此只要加上相應的判斷,並讓HasBorder=true即可達到我希望的效果。修改後代碼如下:
if (cdsHot in State) then
begin
if (cdsChecked in State) or (Button.Down) or (cdsSelected in State) then
ACanvas.Brush.Color := FCheckedAreaSelectColor
else
ACanvas.brush.color := FBSelectColor;
HasBorder := true;
HasBkg := true;
end;
if ((cdsChecked in State) and not (cdsHot in State)) then
begin
ACanvas.Brush.Color := FCheckedAreaColor;
HasBorder := true;
HasBkg := true;
end;
{Modify: Conch 2005-3-10 在Down=true的按鈕上畫出邊框}
if (Button.Down) and not (cdsHot in State) then
begin
HasBorder := true;
HasBkg := false;
end;
//Conch
if (cdsIndeterminate in State) and not (cdsHot in State) then
begin
ACanvas.Brush.Color := FBSelectColor;
HasBkg := true;
end;