1

I have a tool bar and I am using the following procedure to change the color of a rectangle in one of the tool buttons. The ColorDepth of the ImageList is cl24Bit and the DrawingStyle is dsTransparent. The procedure works fine.

procedure TANewMain.BtReplaceHighOnClick(Sender: TObject);
var
  ABitmap: TBitmap;
  ARect: TRect;
begin
  ABitmap := TBitmap.Create;
  try
    ImgList.GetBitmap(1, ABitmap);
    ABitmap.Canvas.Brush.Color := ColorToRGB(clRed); // S04
    ABitmap.Canvas.Pen.Color := ColorToRGB(clBlue);
    ARect := Rect(5, 1, 11, 15);
    ABitmap.Canvas.Rectangle(ARect);
    ImgList.ReplaceMasked(1, ABitmap, clWhite);
  finally
    ABitmap.Free;
  end;
end;

If I add the program to the repository for reuse it works fine. However, if I start a new program from scratch and use the exact same procedure, I get a white button. I made sure that the properties for the image list and the tool bar are the same in both programs. The program that works was written some time ago. Could the problem have anything to do with Windows updates? I am using Windows 10 and Delphi 10.

NGLN
  • 43,011
  • 8
  • 105
  • 200
Rudi
  • 203
  • 2
  • 12

1 Answers1

2

There are two solutions to your problem.

1) Disabling themeing of your application

Disable by unticking the 'Enable Runtime themes' checkbox in 'Project - Options - Application'.

The downside of this is that the application looks as developed for Windows 95.

2) Change following properties of the ImageList

  • ColorDepth: cdDeviceDependent
  • DrawingStyle: dsNormal
  • ImageType: itMask

The result looks like this on Windows 10 (and with respect to the toolbuttons, the same also on Windows 7):

enter image description here

I modified your code to act as a toggle for the buttons, therefore two buttons have the red rectangle.

The numbers are simply 64 x 64 pixel bitmaps with black text on white background.

Caveat: The principle of copying - modifying - copy back repeatedly might lead to reduced quality of the images. A better way could be to have two imagelists, one with the original images and one with the rectangle readily drawn.

Having said that, it appears that the purpose of the rectangle is to indicate some kind of 'active' state. That can be achived also with Down property of the buttons.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • My button does reflect the selected back and foreground colour for highlighting text in a RichEdit control (similar to the underline in the font colour button of Microsoft Word). Thank you. Problem solved. – Rudi Nov 18 '16 at 09:09
  • So what was the problem, W10 does not support 24bit bitmaps any more? – Sertac Akyuz Nov 18 '16 at 10:01
  • @Sertac Akyuz I am using Delphi 10 running on Windows 10. The colour depth of the image list is set to cl24Bit and the runtime themes are disabled. With these settings the procedure gives the desired result. Inspecting the bitmap imported into the image list, using the Windows property dialogue, shows a bit depth of 24. So, Windows 10 / Delphi 10 seem to handle the situation ok. – Rudi Nov 18 '16 at 11:38
  • @Sertac Ohh, I am sure W 10 supports 24bit bitmaps ;) I did really try to trace where things go wrong with OP's setup, but after hitting the wall a couple of times I tried with what I've been using, and with the addition of changing `ImageType` it all fell in place. Not a good explanation, but the best I can produce for now. – Tom Brunberg Nov 18 '16 at 13:40