[SOLVED] Memo And Overlaid Image lazarus / 39-Graphics ---------------------------------------------------------------------- Bazzao · 2017-09-02 01:02 A transparent Image on the form and brought to the front is working fine. However when I make a Memo (same dimensions and position as the Image ) visible the Image moves down the z-order, and no amount of BringToFronts or SendToBacks will cure that. The proof is when the Image is offset from the Memo , the portion not covered can be seen. The Memo just displays information and is not for editing. Replacing with a TLabel is not suitable. I have tried setting the Memo to readonly and disabling it. No success. I have tried disabling the Image. No success. By the way, the Image is broken glass. Is it possible to place an Image over a Memo? Any suggestions? Bazza ---------------------------------------------------------------------- taazz · 2017-09-02 01:12 short answer No there is no way to have a TImage on top of a memo. Slightly longer answer. The TMemo is twincontrol descendant and timage is tgraphicControl descentant tgraphiccontrol is not a full blown control. It does not have its own handle, it is managed completely from the parent which calls its paint method inside its own paint method and forwards to it the required messages and events(not all but most). as a result tgraphiccontrols can be thought as lego for the background only. ---------------------------------------------------------------------- Bazzao · 2017-09-02 01:17 Thanks Taazz. I thought as much. B ---------------------------------------------------------------------- RAW · 2017-09-02 01:27 QuoteIs it possible to place an Image over a Memo? Any suggestions? In a semitransparent way ??? If the memo is not for editing purposes then why not draw the text or semitransparent text on the Image or put the semitransparent Image ontop of a label ??? Or use a graphic lib to draw everything yourself... there are so much ways ...  Why is it better to show text with a memo and not with a label or draw everything yourself ??? Sounds strange to me...  Please solve this... I'm just curious... ---------------------------------------------------------------------- Bazzao · 2017-09-02 04:03 I have no idea how to do that. The text is in the memo. So I assume I need to copy the view of Tmemo as an image and place in another Timage, fiddle with the z-order, and hide the memo. This doesn't work ... 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  FalseMemoImage1.Picture.Bitmap.Assign(Memo1.Brush.Bitmap); B ---------------------------------------------------------------------- RAW · 2017-09-02 23:57 QuoteThe text is in the memo. OK, I guess you are talking about a ready program where a memo is used.... You can play around with this: 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.TextOnPic(pic: TImage; str: String; c: TColor);  Var   lbl: TLabel; Begin  lbl             := TLabel.Create(Self);  lbl.Caption   := str;  lbl.Font.Color  := c;  lbl.Font.Size   := 20;  lbl.Font.Quality:= fqAntialiased;  lbl.Font.Style  := [fsBold];  lbl.WordWrap    := True;  lbl.SetBounds   (pic.Left, pic.Top, pic.Width, pic.Height);  lbl.Parent      := Self;   lbl.BringToFront; End; Procedure TForm1.Button1Click(Sender: TObject); Begin  TextOnPic(Image1, Memo1.Text, clWhite); End; Or you can play around with this: 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.Image1Paint(Sender: TObject);  Var   ts: TTextStyle; Begin  ts:= Image1.Canvas.TextStyle;  ts.SingleLine:= False;   Image1.Canvas.Font.Color  := clBlack;  Image1.Canvas.Font.Name   := 'Arial';  Image1.Canvas.Font.Quality:= fqAntialiased;  Image1.Canvas.Font.Size   := 20;  Image1.Canvas.Font.Style  := [fsBold];  Image1.Canvas.TextStyle   := ts;  Image1.Canvas.TextRect    (Image1.ClientRect, 7, 7, Memo1.Text, ts);  Image1.Canvas.Font.Color  := clLime;  Image1.Canvas.TextRect    (Image1.ClientRect, 5, 5, Memo1.Text, ts); End; ..there are a lot more ways ...  just to get you in the game ...  EDIT: If the text is bigger and you need a real shadow blur or something, then it's probably a good idea to use BGRABitmap or GR32 or any other lib... ---------------------------------------------------------------------- taazz · 2017-09-03 00:25 Well..... Should I but in?........ ah WTH! here comes. first question   What about scroll bars? I'll let you ponder on it for a minute sorry I had to... sorry ---------------------------------------------------------------------- RAW · 2017-09-03 00:53 // broken glass ...  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.Button1Click(Sender: TObject); Begin  TextOnPic(Image1, Memo1.Text, clWhite);  Image2.BringToFront; // broken glass :-) End; There is also Memo1.PaintTo(Image1.Canvas, 0, 0); .. maybe you can paint and save this or use it in any other way... (no transparency though...) @taazz:   hi there... where do you read something about long text or scrolling ???? btw. I can draw you some fine scroll handles or scroll pics and let you scroll very big text... but not right now... I don't know the program so I cannot say if this is a good idea or not... This is just "Show some text ontop of a pic or under another pic"... nothing more...  But I guess you can do a quick fancy component that can handle everything... I don't have time ... I need to go... it's late ... hmmm I mean early... ---------------------------------------------------------------------- Bazzao · 2017-09-03 00:57 All the code is good ... will work on it. Many thanks Raw. For Taazz ... easy there is no scrolling. The text is contained within the memo view. And I was going to do something else today. That can wait. B ---------------------------------------------------------------------- RAW · 2017-09-03 01:03 BTW: If necessary it's easy to scroll a TLabel (Left + Top) ontop of a TImage (or under a TImage)... a lot easier than scrolling some TextOut stuff...    EDIT: ...AND there is something that's called TScrollBar just in case somebody has overlooked it..... ---------------------------------------------------------------------- taazz · 2017-09-03 01:27 well you overshoot as expected. It is only necessary to copy the visual portion of the text maybe one or two text lines more to emulate martial cut off, but I think I'll wait for  your version of the code it sounds more complete just kidding I don't do much pascal now days. ---------------------------------------------------------------------- Bazzao · 2017-09-03 01:43 I had trouble with  TextOnPic(Image1, Memo1.Text, clWhite unknown function. But I moved on to Memo1.PaintTo(Image1.Canvas, 0, 0); Which worked. Here is my code 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   Memo1.PaintTo(FalseMemoImage1.Canvas, 0, 0);  Memo1.Visible:=false;  FalseMemoImage1.BringToFront;  BrokenImage1.BringToFront;  And attached is a screenshot (I had a blue screen version, but was knocked back on size) of the testing app. The memo text is just random text generated from: http://randomtextgenerator.com/ Thanks RAW and taazz ---------------------------------------------------------------------- RAW · 2017-09-03 03:05 QuoteI had trouble with  TextOnPic(Image1, Memo1.Text, clWhite unknown function. This is funny... Take a look at Reply #5 then you can find the function...  BTW: looks nice.... your picture... 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 well you overshoot as expected. ...To scroll a Label is the easiest way that I know... is it necessary ... no... it's easy !!! ---------------------------------------------------------------------- Bazzao · 2017-09-03 03:21 RAW, You are absolutely correct. I never got to that code. That is the trouble when bombarded with solution code - where do you start? Which one? The one or two liners I tried first because they looked like they might work without too much effort. And when one works why look further?. You have to weigh up replying "That's it" to stop the flood or trying every bit of code suggested and then replying. Anyway I'll look at the unused code - helps in my relearning process. I'm glad you liked it, because you wanted the solution. Attached is the blue screen version. Many thanks. B ---------------------------------------------------------------------- RAW · 2017-09-03 05:06 QuoteThat is the trouble when bombarded with solution code - where do you start? Which one? Yes... @taazz: [SCROLL TLABEL] ArrowKey_up / down = slow scrolling ///  CTRL + Arrowkey_up / down = 10 times faster scrolling // for example... This is a very easy way to scroll some text... AND !!!! it looks good with a classic theme. If I use a "Scrollbox" or a "ListBox" then it's working fine, but it looks NOT good. 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 UNIT Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes, SysUtils, Forms, Controls, LCLType, ExtCtrls, StdCtrls, Types;  TYPE  TForm1 = Class(TForm)    Label1: TLabel;    Procedure FormCreate         (Sender: TObject);   Procedure FormKeyDown        (Sender: TObject; Var Key: Word;                                 Shift : TShiftState);   Procedure FormMouseWheelUp   (Sender: TObject; Shift: TShiftState;                               MousePos: TPoint; Var Handled: Boolean);   Procedure FormMouseWheelDown (Sender: TObject; Shift: TShiftState;                               MousePos: TPoint; Var Handled: Boolean);   Procedure ScrollUp           (cSpeed: Cardinal);   Procedure ScrollDown         (cSpeed: Cardinal);     PRIVATE     iFontHeight: Integer;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject);  Var   str: String;   i  : Integer; Begin  DoubleBuffered:= True;  KeyPreview    := True;   For i:= 1 To 500  Do str:= str+'Hello World Hello Hello Hello'+IntToStr(i)+sLineBreak;   Label1.Caption:= str+'END of TEXT';  Label1.SetBounds(0, 0, ClientWidth, ClientHeight);   iFontHeight:= Label1.Canvas.TextHeight('HITMqQiyYöÖ'); End;  Procedure TForm1.ScrollUp(cSpeed: Cardinal);  Var   c: Cardinal; Begin  For c:= 0 To cSpeed  Do   Begin    If Label1.Top >= 0 Then Exit;    Label1.Top:= Label1.Top + iFontHeight;   End; End;  Procedure TForm1.ScrollDown(cSpeed: Cardinal);  Var   c: Cardinal; Begin  For c:= 0 To cSpeed  Do   Begin    If Label1.Top <= ClientHeight - Label1.Height Then Exit;    Label1.Top:= Label1.Top - iFontHeight;   End; End;  Procedure TForm1.FormKeyDown(           Sender: TObject; Var Key: Word; Shift: TShiftState); Begin  If Not (ssCTRL In Shift)  Then   Begin    If Key = VK_UP    Then ScrollUp(1);     If Key = VK_DOWN    Then ScrollDown(1);   End;   If (ssCtrl In Shift)  Then   Begin    If Key = VK_UP    Then ScrollUp(10);     If Key = VK_DOWN  Then ScrollDown(10);   End; End;  Procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;                                MousePos: TPoint; Var Handled: Boolean);  Var   Key: Word; Begin  Key:= VK_UP;  FormKeyDown(Self, Key, Shift); End;  Procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;                                    MousePos: TPoint; Var Handled: Boolean);  Var   Key: Word; Begin  Key:= VK_DOWN;  FormKeyDown(Self, Key, Shift); End; END. BTW: I never tried a TLabel with really big or long text... I guess I would use a VirtualTreeView in that case... don't know... ---------------------------------------------------------------------- Bazzao · 2017-09-03 05:48 Well the solution we have reached is the current view of TMemo can easily be hidden behind broken glass - where it belongs. Mind you I have yet to test it with scrollbar(s) visible, but that was outside the scope of the question. Changing it to TLabel would mean determining the first and last lines visible. And possibly much more complications. But an exercise by itself on TLabel with multiple lines is one for the "Maybe Later" pile. Another exercise is a Transparent TLabel in front of a TMemo, with the visible text duplicated. Would the text align? Or would it be blurry and possibly 3D, if 3D glasses were worn? Do we need text leaping out at you?  B ---------------------------------------------------------------------- RAW · 2017-09-03 06:37 QuoteChanging it to TLabel would mean determining the first and last lines visible. And possibly much more complications.It's easy to use a TLabel inside a TPanel, so you only have to set the panel to clBlue and choose the right height and width. You can scroll the TLabel inside the panel. No first line or last line stuff needed... but there are always a lot solutions possible ... (you can always draw everything yourself or use different ready to use controls...) QuoteAnother exercise is a Transparent TLabel in front of a TMemo, ... I don't really see the reason for that... If you already have got a Label, then you don't need a memo anymore... And if you use Canvas TextOut, then you don't need a TImage or TLabel at all. No control is needed for showing some text... ---------------------------------------------------------------------- taazz · 2017-09-03 06:40 Quote from: Bazzao on September 03, 2017, 07:48:46 amAnother exercise is a Transparent TLabel in front of a TMemo, with the visible text duplicated.  Tlabel inherits from TGraphicControl too. Quote from: Bazzao on September 03, 2017, 07:48:46 amWould the text align? yes and no. if you manage to place the label in the correct spot and use the same font, size etc then yes it should align perfectly. No the correct spot is not the upper left corner of tmemo. Quote from: Bazzao on September 03, 2017, 07:48:46 amOr would it be blurry and possibly 3D, if 3D glasses were worn? Do we need text leaping out at you? not blurry per see but if you offset the label for a pixel or two should create the 3d effect you theorise.