How can I place a label in front of a button without overlapping it? lazarus / 13-General ---------------------------------------------------------------------- Galmer · 2024-03-31 18:06 Hello! I only recently started using Lazarus, so I don’t know many of the nuances. I created TBitBtn and I need to place a label “on top” of it. If this is implemented directly, then the label intercepts button events and the button does not react to anything. I have two options. Either somehow disable the label’s response to events, or somehow “throw” these events onto the button located under it. I would be grateful for any help. Today I spent the whole day trying to understand how TVirtualStringTree works, my head is already hard to think) P.S. The Caption property is not suitable here because it only places text on the side of the image. ---------------------------------------------------------------------- ASerge · 2024-03-31 20:22 Replace TLabel with TStaticText. It can. ---------------------------------------------------------------------- Galmer · 2024-04-01 08:51 Quote from: ASerge on March 31, 2024, 10:22:14 pmReplace TLabel with TStaticText. It can. Thanks for the advice, but it didn't help. Static text, intercepts mouse events just like a label. ---------------------------------------------------------------------- wp · 2024-04-01 09:34 Why don't you use the Caption property of the TBitBtn? You write "The Caption property is not suitable here because it only places text on the side of the image." So, you want to have the Caption above/below the image? Use the button's Layout property for this. Further parameters for affecting the text position are Margin (distance between image and border) and Spacing (distance between text and caption). -1 means in both cases: "automatic selection of value". Or you do not want to display an image at all? Leave the Glyph property empty (or ImageIndex at -1) in this case. ---------------------------------------------------------------------- Galmer · 2024-04-01 10:32 Quote from: wp on April 01, 2024, 11:34:44 amHello! I use the TBitBtn properties - ImageIndex, HotImageIndex and PressImageIndex to set my textures for these events. But at the same time, I need the inscription to be placed in the center of the button. I have attached a picture, there is a button with the inscription "AAC, 64 kbps". The Caption and Layout properties are not suitable here, because I need to place the caption not on the side, but above the button - on top of it. ---------------------------------------------------------------------- cdbc · 2024-04-01 10:46 Hi Use "TSpeedButton" instead of TBitButton... It has a 'OnPaint' event, so when /push comes to shove/, you can use that to paint your text on the button, however you please.  ps.: The rest of the properties seem equivalent to TBitButton Regards Benny ---------------------------------------------------------------------- wp · 2024-04-01 10:47 TBitBtn.Layout in action in the attached project QuoteI need to place the caption not on the side, but above the buttonAbove = outside? Then I don't understand why you cannot use a Label or StaticText... Please post a drawing demonstrating what you want the button to look like. ---------------------------------------------------------------------- Galmer · 2024-04-01 12:16 I don’t know spoken English well, so I use a translator. Sorry if I don't express myself clearly. Here is a project with an example of what I need to achieve. ---------------------------------------------------------------------- wp · 2024-04-01 13:20 Now I understand (yes, this "above", "on top of it" has two meanings...) The following code implements a handler for the OnPaint event of the associated SpeedButton: it queries the button state (pressed, mouse is over button, or not)gets the corresponding images from the imagelist and adjusts the button's font (bold and aqua when pressed, normal and white otherwise)stretchdraws the image over the entire buttondraws the button's caption centered over the image.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 uses  LCLIntf, LCLType; procedure TForm1.SpeedButton3Paint(Sender: TObject);var  P: TPoint;  idx: Integer;  bmp: TBitmap;  R: TRect;  ts: TTextStyle;  mousePressed: Boolean;  btn: TSpeedButton;begin  // Exit when event is not fired by a speedbutton  if (Sender is TSpeedButton) then    btn := TSpeedButton(Sender)  else    exit;   // Detect whether the mouse currently is pressed  mousePressed := (GetKeyState(VK_LBUTTON) < 0);   // Detect whether the mouse currently is inside the speedbutton  P := btn.ScreenToClient(Mouse.CursorPos);  R := Rect(0, 0, btn.Width, btn.Height);  if PtInRect(R, P) then  begin    if mousePressed then      idx := 2      // idx identifies the image index needed from the ImageList    else      idx := 1  end else    idx := 0;   // create a bitmap for the image  bmp := TBitmap.Create;  try    // Extract the image from the imagelist for the specified index into the bitmap    ImageList.GetBitmap(idx, bmp);    // Stretch-draw the bitmap to fit into the bounds of the speedbutton (R)    btn.Canvas.StretchDraw(R, bmp);    // Get the textstyle currently active in the speedbutton's canvas...    ts := btn.Canvas.TextStyle;    // ... and adjust it to center text horizontally    ts.Alignment := taCenter;    // ... and vertically inside the given rectangle (R)    ts.Layout := tlCenter;    // Apply the speedbutton's Font to the canvas    btn.Canvas.Font.Assign(btn.Font);    // Modify the font depending on the mouse state.    if mousePressed then    begin      btn.Canvas.Font.Style := [fsBold];      btn.Canvas.Font.Color := clAqua;    end else    begin      btn.Canvas.Font.Style := [];      btn.Canvas.Font.Color := clWhite;    end;    // Draw the text into the rectangle R using the canvas's TextStyle.    btn.Canvas.TextRect(R, 0, 0, btn.Caption, ts);  finally    // Destroy the temporary bitmap    bmp.Free;  end;end;     I don't know how familiar you are with events in Lazarus: copy the above code into your form's codein the interface section of the form's unit, add the line "procedure SpeedButton3Paint(Sender: TObject);" immediately above the "private" in TForm's declaration. in the object inspector select the speed button. On page "Events" of the object inspector click on dropwdown arroy next to OnPaint, and select the previously added procedure. This will assign this procedure to the OnPaint event of the button which will be executed whenever the speedbutton is repainted.Repeat with other speedbutton which should share the same code. ---------------------------------------------------------------------- Galmer · 2024-04-01 17:46 Thank you very much! Your advice helped me, but I took only part of the code with text rendering, this was enough for me. 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.ButtonSourcesPaint(Sender: TObject);var   R: TRect;   ts: TTextStyle; begin   R := Rect(0, 0, ButtonSources.Width, ButtonSources.Height);    // Get the textstyle currently active in the speedbutton's canvas...   ts := ButtonSources.Canvas.TextStyle;   // ... and adjust it to center text horizontally   ts.Alignment := taCenter;   // ... and vertically inside the given rectangle (R)   ts.Layout := tlCenter;    ButtonSources.Canvas.Font.Color := clHighlightText;    ButtonSources.Canvas.TextRect(R, 0, 0, 'AAC, 64 kbps', ts);end;  But when I used your code in full, when replacing the texture of the button from the code, for some reason it was drawn darker than when setting the texture through properties. It is not clear what this is connected with. I'll attach a screenshot to make it clearer. Thanks again! It is very difficult to find any detailed resources on Lazarus, at least for me) ---------------------------------------------------------------------- What I can do · 2024-04-29 01:05 I'm not a pro in any sort but I have done something similar. I think I made a button that was on/ off I use correldraw to make tow version of a bitmap so if you are a fair artist paint brush will do. I can't remember the exact button but any type with two version of bitmaps (active/inactive) in the settings should work. The on bitmap was bright blue with ON in the center colored red then the off was a bitmap with off in the center that was dark red while the rest was light gray. Sorry I don't have any code on hand but I think that should do it.  Hope this helps, keep on coding.. ---------------------------------------------------------------------- Чебурашка · 2024-04-29 22:07 I had similar situation, I just created a callback method and assigned to both the components. Procedure therealclick Button.onclick := therealclick Label.onclick := therralclick