[SOLVED]Cannot center image in tSpeedButton lazarus / 31-LCL ---------------------------------------------------------------------- CM630 · 2018-04-25 11:18 I have a speed button (W=24; H=24 px), placed in a toolbar. My code is   if stQuickTransOn     then imagelist1.GetBitmap(0,SpeedButton1.Glyph)     else imagelist1.GetBitmap(1,SpeedButton1.Glyph); Images are stored in imglImagesOnOff, all images in it are 24x24 pixels. imglImagesOnOff is itself 24 pixels wide. When I have not touched default values of the speed button image is drawn OUTSIDE(above) the button. I tried various settings, but could not center the image on both axises. I have also tried Center of the images in imagelist1, but they got garbled, scrambled... etc. Should I use some other control instead of TSpeedButton? (a sample is attached) ---------------------------------------------------------------------- ASerge · 2018-04-25 11:56 The image is centered, but the arrow in the image is not centered. Correct the image. ---------------------------------------------------------------------- RayoGlauco · 2018-04-25 12:00 I usually use  tBitBtn and I like it. I have no problem, and the images are placed in the center. Anyway, I think your button must be greater than 24x24 if you want it to contain 24x24 images, because there has to be some margin. ---------------------------------------------------------------------- CM630 · 2018-04-25 12:09 Quote from: ASerge on April 25, 2018, 01:56:49 pmThe image is centered, but the arrow in the image is not centered. Correct the image. It is offset one pixel to the left and is vertically centered. And even if it was not so, I except it should not be drawn oustside (above) the button, as it happens. Quote from: RayoGlauco on April 25, 2018, 02:00:37 pmAnyway, I think your button must be greater than 24x24 if you want it to contain 24x24 images, because there has to be some margin. I increased it to 28x28, and still image is alligned top-left. ---------------------------------------------------------------------- RayoGlauco · 2018-04-25 12:35 Maybe this is a kind of bug?  Using your code, image is placed top- left. If I manually put an image on the button, the result is different, as the attached image shows. If you place on your button some image (same size: 24x24) in design time, I think then the images placed by code may be ok. ---------------------------------------------------------------------- balazsszekely · 2018-04-25 12:51 Did you take into account ShowCaption, Caption Layout properties? More over the arrow is not in the center of your image. Set ShowCaption to false and LayOut to glyphRight + move the arrow to the middle and you should be good to go. ---------------------------------------------------------------------- CM630 · 2018-04-25 12:55 Quote from: RayoGlauco on April 25, 2018, 02:35:40 pm Maybe this is a kind of bug?  Using your code, image is placed top- left. If I manually put an image on the button, the result is different, as the attached image shows. If you place on your button some image (same size: 24x24) in design time, I think then the images placed by code may be ok. Yes, it is centered when I put the image at design time. Quote from: GetMem on April 25, 2018, 02:51:28 pm Did you take into account ShowCaption, Caption Layout properties? More over the arrow is not in the center of your image. Set ShowCaption to false and LayOut to glyphRight + move the arrow to the middle and you should be good to go. I have already tried ShowCaption=false  and LayOut=Everything possible. How am I to move the arrow to the middle? ---------------------------------------------------------------------- wp · 2018-04-25 12:59 Your image originally looks like 16x16, but your image list is 24x24. If I use an image from which I know for sure that it is 24x24 it works correctly. And if I put the 16x16 image into a 16x16 imagelist, everything works fine as well. Probably when you put the 16x16 into the 24x24 image list the imagelist has its own ideas of how to handle this cas. ---------------------------------------------------------------------- CM630 · 2018-04-25 13:19 Yes @wp, that should be it. And imagelist cannot center properly. It has sucha property, results are desastrous. ---------------------------------------------------------------------- taazz · 2018-04-25 13:21 Quote from: CM630 on April 25, 2018, 03:19:12 pmYes @wp, that should be it. And imagelist cannot center properly. It has sucha property, results are desastrous. change the transparent color to something else than default before centering ---------------------------------------------------------------------- CM630 · 2018-04-25 13:36 There is sth. wrong with ImageList. 1. When I set transparency to something else (i.e. Fucscia) I get purle artefacts aroud the image. If I used the default colour I get the image on a black background./ 2. When adding an image 16x16 with red stripes in an image list 24x24 they are displayed as yellow stripes. ---------------------------------------------------------------------- wp · 2018-04-25 13:56 No nothing wrong with the image list. You're just not using it correctly. When the image is smaller than the size assumed by the imagelist then the pixels outside the image are undefined. BTW, this might have changed with the new image list of Laz trunk which can scale the images to the required size. ---------------------------------------------------------------------- CM630 · 2018-04-25 16:12 Quote from: wp on April 25, 2018, 03:56:50 pm ...the pixels outside the image are undefined... Could this explain that Quote from: СМ6302. When adding an image 16x16 with red stripes in an image list 24x24 they are displayed as yellow stripes. These stripes are inside the image.