ComboBox and PopupMenu Customization using HTML Text required

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #70502
    Koushik Halder
    Participant

    Please find my code as follows:

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, sSkinProvider, sSkinManager,
      Vcl.StdCtrls, Vcl.Mask, sMaskEdit, sCustomComboEdit, sComboBox, Vcl.Menus,
      sEdit, acntTypes;
    
    type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        M1: TMenuItem;
        M2: TMenuItem;
        M3: TMenuItem;
        sComboBox1: TsComboBox;
        sSkinManager1: TsSkinManager;
        sSkinProvider1: TsSkinProvider;
        sEdit1: TsEdit;
        procedure FormCreate(Sender: TObject);
        procedure sComboBox1GetItemDrawData(Sender: TObject;
          var ItemDrawData: TacItemDrawData);
        procedure sSkinManager1GetMenuExtraLineData(FirstItem: TMenuItem;
          var SkinSection, Caption: string; var Glyph: TBitmap;
          var LineVisible: Boolean);
        procedure sSkinManager1GetPopupItemData(Item: TMenuItem;
          State: TOwnerDrawState; ItemData: TacMenuItemData);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      PopupMenu1.AutoPopup := true;
      sComboBox1.Items.BeginUpdate;
      try
        begin
          sComboBox1.Items.Clear;
          sComboBox1.Items.Add('A.  Fox');
          sComboBox1.Items.Add('B.  Tiger');
          sComboBox1.Items.Add('C.  Elephant');
        end
      finally
        begin
          sComboBox1.Items.EndUpdate;
        end
      end;
      sComboBox1.Font.Color := clBlue;
      sComboBox1.Skindata.CustomFont := true;
      sSkinManager1.MenuSupport.UseExtraLine := true;
    end;
    
    procedure TForm1.sComboBox1GetItemDrawData(Sender: TObject;
      var ItemDrawData: TacItemDrawData);
    begin
    //
    end;
    
    procedure TForm1.sSkinManager1GetMenuExtraLineData(FirstItem: TMenuItem;
      var SkinSection, Caption: string; var Glyph: TBitmap;
      var LineVisible: Boolean);
    begin
    //
    end;
    
    procedure TForm1.sSkinManager1GetPopupItemData(Item: TMenuItem;
      State: TOwnerDrawState; ItemData: TacMenuItemData);
    begin
      case Item.Tag of
        1:  begin
          //
          ItemData.Font.Style := [];
          ItemData.Font.Size := 9;
          ItemData.Font.Color := clBlue;
        end;
    
        2: begin
          ItemData.Font.Style := [];
          ItemData.Font.Size := 9;
          ItemData.Font.Color := clBlue;
        end;
    
        3: begin
          ItemData.Font.Style := [];
          ItemData.Font.Size := 9;
          ItemData.Font.Color := clBlue;
        end;
    
      end;
    end;
    
    end.

    I need to make ComboBox items as follows:
    A. Fox
    B. Tiger
    C. Elephant

    and need to make PopupMenu items as follows:
    A. Fox
    B. Tiger
    C. Elephant

    How this can be implemented.

    #70526
    Support
    Keymaster

    Hello! Could you upload a full project, please?

    #70556
    Koushik Halder
    Participant

    Please find attached herewith my project. My sComboBox1 items will be as follows:
    A. Fox
    B. Tiger
    C. Elephant
    Any how I have coded my requirement in sComboBox1 but unable to get my required result as I mentioned above. Please help to rectify.

    But no option for HTML Coded PopupMenu Items. So you are requested to design your own PopupMenu.

    Attachments:
    You must be logged in to view attached files.
    #70574
    Support
    Keymaster

    Thank you.
    Try this code in the OnGetItemDrawData:

    procedure TForm1.sComboBox1GetItemDrawData(Sender: TObject; var ItemDrawData: TacItemDrawData);
    begin
      ItemDrawData.HtmlText := ItemDrawData.Text; // Copy text for a current Item
      ItemDrawData.Text := ''; // Use HtmlText
    end;

    This event is called for an each Item and text should be different for each Item.
    By the way, ‘Cyan’ color is not handled. Main 16 colors are added for parsing.
    You can use a number format for colors there.

    #70576
    Koushik Halder
    Participant

    Thanks for your code. Now sComboBox works perfectly. But PopupMenu Items customization remaining. Please launch your own PopupMenu.

    #70589
    Koushik Halder
    Participant

    Now another problem has come to me. When I am selecting any item in ComboBox it shows HTML Coded Text for example for sComboBox1.Items[0] it shows <b><font color=Yellow>A.</font></b><font color=Red> Fox</font> instead of A. Fox[/color]. But your ComboBox Demo is OK. I am trying to find it out what you have coded more but unable to find. Please mention.

    #70601
    Support
    Keymaster

    Maybe you can upload another demo?

    #70602
    Koushik Halder
    Participant

    Please find my project attached herewith.

    Attachments:
    You must be logged in to view attached files.
    #70612
    Koushik Halder
    Participant

    I have updated my project.

    Attachments:
    You must be logged in to view attached files.
    #70615
    Support
    Keymaster

    Thank you, I’ll check it soon.

    #70661
    Koushik Halder
    Participant

    Please do the needful.

    #70671
    Support
    Keymaster

    Look, the Text property receives html tags from the Items list, when selected.
    We should think how to avoid this standard behavior…
    Maybe new property like ‘MakeTextPlain’ will help?

    #70678
    Koushik Halder
    Participant

    Yes! Please implement it.

    #70694
    Koushik Halder
    Participant

    Thank you! I have checked and it is working fine.

    #70701
    Koushik Halder
    Participant

    MakeTextPlainis working partially. If any ComboBox ItemIndex is other than -1 i.e any item is selected then if I click any component like Button, Editand Memoetc. then selected Item of ComboBoxagain becomes HTML RAW DATA not the plain text.

    #70707
    Support
    Keymaster

    Hi! I will check it.

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.