Jump to content
Mark Williams

TButtonedEdit Styles and transparency

Recommended Posts

When using a dark theme with TButtonedEdit and an imagelist with DrawingStyle set to dsTransparent, the image always shows with a white background. That's obviously fine when the edit box is white, but not when it is dark.

 

My images in the imagelist have a background colour of clFuschia. For some reason I can't change the transparent color in the imageList's editor. It is disabled and clDefault is selected. 

 

So I tried another approach, creating an imageList at runtime and adding masked images to it as follows:

Function GetTransparentImageList(Owner:TComponent; SourceImages:TImageList; BMPIndex:Integer):TImageList;
  var
    bmp:TBitmap;
begin
  bmp:=TBitmap.Create;
  try
    if SourceImages.GetBitmap(BMPIndex, bmp) then
      begin
        Result:=TImageList.Create(Owner);
        With Result do
          begin
			DrawingStyle:=dsTransparent; //tried with and without for all three color options below
            AddMasked(bmp, clNone); //tried with clFuchsia and clDefault
          end;
      end;
  finally
    bmp.Free;
  end;
end;

Still the TButtonedEdit stubbornly shows the button image with a white background.

 

Am I missing something?

Share this post


Link to post
42 minutes ago, pyscripter said:

https://quality.embarcadero.com/browse/RSP-26633

The report contains a solution.

Thanks for the link. It didn't seem to work for me. However, it gave me the idea to change my function to repaint the background of the glyph. Now works and will have to do for now.

Function GetTransparentImageList(Owner:TComponent; SourceImages:TImageList; BMPIndex:Integer):TImageList;
  var
    bmp:TBitmap;
begin
  bmp:=TBitmap.Create;
  try
    if SourceImages.GetBitmap(BMPIndex, bmp) then
      begin
        Result:=TImageList.Create(Owner);
        With Result do
          begin
            bmp.Canvas.Brush.Color:=StyleServices.GetSystemColor(clWindow);;
            bmp.Canvas.FloodFill(0, 0, bmp.canvas.Pixels[0, 0], fsSurface);
            AddMasked(bmp, clFuchsia);
          end;
      end;
  finally
    bmp.Free;
  end;
end;

 

Share this post


Link to post

Hi, I have same problem (but I use system image list), but I could not fix it. I tried all the solutions proposed in this topic, but they doesn't work. So I want to change TEditButton's paint method (so I can use proper color for TEditButton.TGlyph.Canvas.Brush.Color), but I don't know how. Can somebody help me? Thanks.

Share this post


Link to post

Resolved using @GPRSNerd's solution and clWindow (so change from "dark" theme to light, the background color of tbuttonededit is always right). Thanks.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×