首页 > 其他分享 >再次修复combobox下拉背景颜色

再次修复combobox下拉背景颜色

时间:2024-04-26 16:45:13浏览次数:14  
标签:begin end 修复 combobox 下拉 State Brush Font FCanvas

2023年2月写的修复lazarus combobox的下拉列表在linux时没有高亮显示选中的item的问题,需然解决了显示问题,但下拉列表的颜色在银河麒麟是灰黑色,和应用的颜色明显不搭,想要win一样样式,如果要改变下拉背景颜色,可以按以下修改就可以,当然,如果不想用白色,可以改为想要的颜色。
打开lazarus/lcl/include/customcombobox.inc
按以下修改后重新编译就可以.

procedure TCustomComboBox.DrawItem(Index: Integer; ARect: TRect;
  State: TOwnerDrawState);
begin
  //TControlCanvas(FCanvas).UpdateTextFlags;
  if Assigned(FOnDrawItem) then
    FOnDrawItem(Self, Index, ARect, State)
  else
  begin
    if not (odBackgroundPainted in State) then
      FCanvas.FillRect(ARect);
    InternalDrawItem(Self, FCanvas, ARect, Items[Index])
  end;
end;

改该:

procedure TCustomComboBox.DrawItem(Index: Integer; ARect: TRect;
  State: TOwnerDrawState);
begin
  //TControlCanvas(FCanvas).UpdateTextFlags;
  //2022.05.28 LBZ
  {$ifdef linux}
  if (FDroppedDown) then
  begin
    if  (GetItemIndex=index)  then   //当为ItemIndex时高亮显示item
    begin
      FCanvas.Brush.Color := clHighlight;
      FCanvas.Font.Color :=  clHighlightText or clHighlight;
      State:=[odSelected];
    end
    Else
    begin
     if not (odBackgroundPainted in State) then
      FCanvas.Brush.Color := clWhite;//背景颜色
      State:=[odFocused];
    end;
    //FCanvas.Font.Color:= clMenuText;
  end;
  {$endif}
  //2022.05.28 LBZ
  if Assigned(FOnDrawItem) then
    FOnDrawItem(Self, Index, ARect, State)
  else
  begin
    if not (odBackgroundPainted in State) then
      FCanvas.FillRect(ARect);
    InternalDrawItem(Self, FCanvas, ARect, Items[Index])
  end;
end;

修改将下拉是用系统主题颜色的:

修改后,用自定的颜色(和win一样的颜色):

 


procedure TCustomComboBox.LMDrawListItem(var TheMessage : TLMDrawListItem);
begin
  with TheMessage.DrawListItemStruct^ do
  begin
    FCanvas.Handle := DC;
    if Font<>nil then
    begin
      FCanvas.Font := Font;
      FCanvas.Font.PixelsPerInch := Font.PixelsPerInch;
    end;
    if Brush<>nil then
      FCanvas.Brush := Brush;
    if (ItemID <> UINT(-1)) and (odSelected in ItemState) then
    begin
      FCanvas.Brush.Color :=clHighlight;
      FCanvas.Font.Color := clHighlightText;
    end;
    DrawItem(ItemID, Area, ItemState);
    if odFocused in ItemState then
      {DrawFocusRect(hDC, rcItem)};
    FCanvas.Handle := 0;
  end;
end;

改为

procedure TCustomComboBox.LMDrawListItem(var TheMessage : TLMDrawListItem);
begin
  with TheMessage.DrawListItemStruct^ do
  begin
    FCanvas.Handle := DC;
    if Font<>nil then
    begin
      FCanvas.Font := Font;
      FCanvas.Font.PixelsPerInch := Font.PixelsPerInch;
    end;
    if Brush<>nil then
      FCanvas.Brush := Brush;
    if (ItemID <> UINT(-1)) and (odSelected in ItemState) then
    begin
      FCanvas.Brush.Color :=clHighlight;
      FCanvas.Font.Color := clHighlightText;
      {$ifdef linux}
      FCanvas.FillRect(Area);
      ItemState:=[odBackgroundPainted];
      {$endif}
    end;
    DrawItem(ItemID, Area, ItemState);
    if odFocused in ItemState then
      {DrawFocusRect(hDC, rcItem)};
    FCanvas.Handle := 0;
  end;
end;

 

标签:begin,end,修复,combobox,下拉,State,Brush,Font,FCanvas
From: https://www.cnblogs.com/qiufeng2014/p/18160390

相关文章

  • 代码报错不用愁,CodeGeeX一键完成代码修复、错误解释的功能上线了!
    作为一名开发者,你一定遇到过在编写代码时出现的各种错误。这些错误可能是语法错误、运行时错误或者逻辑错误。处理这些错误通常需要花费大量的时间和精力,特别是当你对错误的原因一无所知时。CodeGeeX的v2.7.4版本最新上线的代码修复和错误解释功能,让你在解决代码错误的问题上,变得......
  • windows系统修复笔记
    windows修复笔记 1.检查修复硬盘chkdskC:/R/f2. 修复引导Bootrec.exe/fixmbrBootrec/fixbootbootrec/RebuildBcdbcdbootc:\windows/sc:3.系统文件修复sfc/SCANNOW 参考连接:还原或修复运行WindowsServerEssentials的服务器|MicrosoftLear......
  • dotnet 修复 GitHub Action 构建过程提示 NETSDK1127 错误
    本文告诉大家,如何修复GitHubAction构建过程提示errorNETSDK1127:ThetargetingpackMicrosoft.WindowsDesktop.App.WindowsFormsisnotinstalled.Pleaserestoreandtryagain.错误在进行GitHubAction构建时,如果自己的项目是一个旧项目,采用旧的.NETSDK版本,将可......
  • dotnet 修复多框架 TargetFrameworks 包含不受支持平台导致构建失败
    本文将告诉大家如何修复dotnet项目里的多框架TargetFrameworks如果包含了当前系统无法支持的平台时,如何进行跳过。解决在Linux平台构建时提示MacCatalyst不受支持而构建失败故事的背景是我期望在GitHub的Action里面构建一个项目,我期望能够在Windows和Linux和Ma......
  • 记 dotnet 8.0.4 修复的 WPF 的触摸模块安全问题
    本文记录dotnet8.0.4版本修复的WPF的触摸模块安全问题,此问题影响所有的.NET版本,修复方法是更新SDK和运行时宣布安全漏洞地址:https://github.com/dotnet/wpf/issues/9003安全漏洞宣布地址:https://github.com/dotnet/announcements/issues/303漏洞代号:CVE-2024-21409......
  • 修复 Debian 安装 dotnet 失败 depends on ca-certificates
    本文记录我在Debian安装dotnet失败,报错信息是packages-microsoft-proddependsonca-certificates;however:Packageca-certificatesisnotinstalled.一开始按照官方的以下代码例子进行安装packages-microsoft-prod.deb文件,命令如下sudodpkg-ipackages-microsof......
  • apache poi 实现下拉框级联
    场景需求最近在项目中遇到个需求,需要提供一个批量导入的功能,常规做法就是提交excel模版文件,然后就是解析该文件读取数据,这时的模版文件在用户输入方面是没有限制的,用户输入啥就是啥,后台在解析的时候对值进行判断数据是否合法;在现有的业务场景下,是可以进一步限制用户的输入的,这一......
  • C#导出execl带下拉项数据巨多方案
    这个方法可以解决大数据下拉问题///<summary>///这个是正对整个execel不是针对某列,所有必须有IWorkbookworkbook,解决下拉数据量过多,导出之后点击没有反应///</summary>///<paramname="workbook"></param>///<paramname="sheet"......
  • EasyPoi 导出xlsx下拉列表过长问题解决
    问题描述:通过EasyPoi导出Excel带下拉框字段时,下拉框内值超过255时,会报错Stringliteralsinformulascan'tbebiggerthan255charactersASCII解决方案:额外创建sheet页去存储下拉框内数据,然后从这个sheet页中读取下拉框数据存到下拉列表中,最后需将额外创建的sheet隐藏......
  • Devexpress GridControl下拉框实现联动
    实现效果1.先在设计界面绑定数据列1.点击设计器2.绑定数据列2.绑定GridView的FocusedRowChanged事件//定义两个下拉框_RIcmbtype:不良分类_RIcmbdefect:不良信息RepositoryItemComboBox_RIcmbtype=newRepositoryItemComboBox();RepositoryItemComboBox......