Jump to content
Mark Williams

TVirtualImageList Custom component

Recommended Posts

I have a custom component derived from TPanel. There are several other components included including a TToolBar. There was also a TImageList which loaded bitmaps from a resource file to provide the icons for the toolbar.

 

I'm finally getting around to trying to update this to work with TVirtualImageList and transparent PNG files (24 x 24) rather than bitmaps. It works, but is not scaling properly. On higher resolution monitors the toolbuttons are far too small.

 

I suspect my problem is with the scaling of the toolbar rather than the imagelist. But I'm not entirely sure that's correct or what to do about it. The relevant code is below.

 

  FImageList := TVirtualImageList.create(self);
  FImageList.SetSize(TargetSize, TargetSize);
  FImageList.ImageCollection := FImageCollection;
  FImageList.DisabledGrayscale := true;

   FImageList.Height := 24;
   FImageList.Width := 24;

   FToolBar := TToolbar.create(self);

  FToolBar.parent := self;

  with FToolBar do
  begin
    Height := 36;
    ButtonWidth := 35;
    ButtonHeight := 35;   
    align := alTop;
    ShowHint := true;
    AutoSize := true;
    Wrapable := true;
  end;

 

Share this post


Link to post

The higher the resolution is, the smaller a 24x24 image is going to look. You need multiple images of different sizes, and then choose the appropriate size for a given resolution.  Are you doing that?  The whole point of TImageCollection is to provide images of different sizes/resolutions, and then TVirtualImageList presents those images at a given size/resolution.  Where are you making adjustments based on the current resolution?

Edited by Remy Lebeau

Share this post


Link to post
2 hours ago, Remy Lebeau said:

The whole point of TImageCollection is to provide images of different sizes/resolutions, and then TVirtualImageList presents those images at a given size/resolution.

It also scales the image if the requested size is not present.

Share this post


Link to post

I think TVirtualImageList is automatically scaled when DPI changes only when TVirtualImageList is placed on a TForm/TFrame (look for SendChangeScaleMessage in the VCL code).

So you'll have to override the panel ChangeScale method and set the image list size.

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

×