Mini-Q: SpeedButton's Glyph: possible to manipulate it's pos a bit? lazarus / 31-LCL ---------------------------------------------------------------------- d7_2_laz · 2024-10-25 19:58 Actually i'm using a very advanced custom button also for a few contexts for which they might be simply overkill. For those, i could shorten the code simply by using a SpeedButton (or BitBtn) instead, but a little quest. came up: it's about to visually indicate even better if the button is clicked/pressed, in so far it appears that it moves a bit down/right. Experimenting with the SpeedButton  -   IS: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.SpeedButton1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin     with SpeedButton1 do begin         LayOut := blGlyphBottom;         Left := Left + 1;       Top := Top + 1;     end;end; procedure TForm1.SpeedButton1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin   with SpeedButton1 do begin       LayOut := blGlyphLeft;       Left := Left - 1;       Top := Top - 1;   end;end; WANTED: when clicked, additionally the Glyph is shifted one pixel down. That's what the advanced custom button's canvas Draw is actually doing, and the effect is that the visual indication is somehow stronger. But SpeedButton's Glyph has no "Top" or "Left" property for that. Any way around? Yes, i'm aware, the question is a bit academic, sorry for that inconvenience ---------------------------------------------------------------------- d7_2_laz · 2024-10-25 20:21 As short illustration what's targeted a short screen video (pls note, the round circle you will also see is not from the control but is an addition from the screen recording tool). ---------------------------------------------------------------------- wp · 2024-10-25 21:07 If you'd be satisfied with a shift only in one dimension there would be a simple solution based on the Margin property of the SpeedButton. Margin is the distance of the glyph from the left side of the button if Layout is blGlyphLeft, or from the right/top/bottom sides respecitively if Layout is blGlyphRight/blGlyphTop/blGlyphBottom. The default value is -1 which means: centered inside the space available for the glyph. But there is also a Spacing property which defines the distance between glyph and caption. In the following code the glyph performs a down/up movement when the button is clicked: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function DefaultMargin(ASpeedButton: TSpeedButton): integer;begin  Result := (ASpeedButton.Height - ASpeedButton.Glyph.Height) div 2 - 2;  // -2 is empirical to get good centering (at least on my test button)end; procedure TForm1.FormCreate(Sender: TObject);begin  SpeedButton1.Margin := DefaultMargin(SpeedButton1);end; procedure TForm1.SpeedButton1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  SpeedButton1.Margin := DefaultMargin(SpeedButton1) + 1;end; procedure TForm1.SpeedButton1MouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  SpeedButton1.Margin := DefaultMargin(SpeedButton1);end; However, this works only for a single dimension. If you need movement in two directions then, I think, you have to go the hard way and override the Paint method. Maybe you can take advantage of the procedure MeasureDraw which calculates glyph and text positions, but it is not virtual, and the results that you need are only in local variables... ---------------------------------------------------------------------- d7_2_laz · 2024-10-25 22:14 Before going as last resort the hard way (replication of the paint) .... yes, this is nice too! I'll see a slight internal horizontal movement of the glyph to the right during the pressed state (Gif attached), not vertically up/down -> how had you set LayOut (i had blGlyphLeft. If i preset blGlyphTop, it achieves up/down, but the original state of the control appears somehow unbalanced, see image). //Had tried also with Margin (also negative Margin < -1), Spacing. BorderSpacing before but had not seen a useful effect; hm, maybe wrong combination with Layout applied here). Good hint and advice wp, thank you! ---------------------------------------------------------------------- d7_2_laz · 2024-10-26 09:00 With this combination i get a somehow interesting (and symetric appearing) result; seems a little exaggerated though: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //FormCreate:   SpeedButton1.LayOut := blGlyphLeft;   SpeedButton1.Margin := DefaultMargin(SpeedButton1); //SpeedButton1MouseDown   SpeedButton1.LayOut := blGlyphTop;   SpeedButton1.Margin := DefaultMargin(SpeedButton1) + 1; //SpeedButton1MouseUp   SpeedButton1.LayOut := blGlyphBottom;   SpeedButton1.Margin := DefaultMargin(SpeedButton1); ---------------------------------------------------------------------- d7_2_laz · 2024-10-26 12:23 Even better ... ... and fairly good enough to not have to invest time in Paint replication for this little animation: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //FormCreate:   SpeedButton1.LayOut := blGlyphLeft;   SpeedButton1.Margin := DefaultMargin(SpeedButton1); //SpeedButton1MouseDown   //SpeedButton1.LayOut := blGlyphTop;  // Replace by:   SpeedButton1.LayOut := blGlyphLeft;   SpeedButton1.Margin := DefaultMargin(SpeedButton1) + 1; //SpeedButton1MouseUp   SpeedButton1.LayOut := blGlyphBottom;   SpeedButton1.Margin := DefaultMargin(SpeedButton1); Edit: The function "DefaultMargin" is defined as shown from wp in reply #2