Recent

Author Topic: [SOLVED] Memo And Overlaid Image  (Read 8139 times)

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
[SOLVED] Memo And Overlaid Image
« on: September 02, 2017, 03:02:26 am »
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
« Last Edit: September 09, 2017, 06:53:42 am by Bazzao »
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Memo And Overlaid Image
« Reply #1 on: September 02, 2017, 03:12:06 am »
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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Memo And Overlaid Image
« Reply #2 on: September 02, 2017, 03:17:39 am »
Thanks Taazz. I thought as much.

B
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #3 on: September 02, 2017, 03:27:00 am »
Quote
Is 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...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Memo And Overlaid Image
« Reply #4 on: September 02, 2017, 06:03:29 am »
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][+][-]
  1.  
  2. FalseMemoImage1.Picture.Bitmap.Assign(Memo1.Brush.Bitmap);  
  3.  


B
« Last Edit: September 02, 2017, 06:48:22 am by Bazzao »
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #5 on: September 03, 2017, 01:57:32 am »
Quote
The 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][+][-]
  1. Procedure TForm1.TextOnPic(pic: TImage; str: String; c: TColor);
  2.   Var
  3.    lbl: TLabel;
  4.  Begin
  5.   lbl             := TLabel.Create(Self);
  6.   lbl.Caption     := str;
  7.   lbl.Font.Color  := c;
  8.   lbl.Font.Size   := 20;
  9.   lbl.Font.Quality:= fqAntialiased;
  10.   lbl.Font.Style  := [fsBold];
  11.   lbl.WordWrap    := True;
  12.   lbl.SetBounds   (pic.Left, pic.Top, pic.Width, pic.Height);
  13.   lbl.Parent      := Self;
  14.  
  15.   lbl.BringToFront;
  16.  End;
  17.  
  18. Procedure TForm1.Button1Click(Sender: TObject);
  19.  Begin
  20.   TextOnPic(Image1, Memo1.Text, clWhite);
  21.  End;


Or you can play around with this:
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Image1Paint(Sender: TObject);
  2.   Var
  3.    ts: TTextStyle;
  4.  Begin
  5.   ts:= Image1.Canvas.TextStyle;
  6.   ts.SingleLine:= False;
  7.  
  8.   Image1.Canvas.Font.Color  := clBlack;
  9.   Image1.Canvas.Font.Name   := 'Arial';
  10.   Image1.Canvas.Font.Quality:= fqAntialiased;
  11.   Image1.Canvas.Font.Size   := 20;
  12.   Image1.Canvas.Font.Style  := [fsBold];
  13.   Image1.Canvas.TextStyle   := ts;
  14.   Image1.Canvas.TextRect    (Image1.ClientRect, 7, 7, Memo1.Text, ts);
  15.   Image1.Canvas.Font.Color  := clLime;
  16.   Image1.Canvas.TextRect    (Image1.ClientRect, 5, 5, Memo1.Text, ts);
  17.  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...
« Last Edit: September 03, 2017, 02:16:01 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Memo And Overlaid Image
« Reply #6 on: September 03, 2017, 02:25:23 am »
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 :P

sorry I had to... sorry
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #7 on: September 03, 2017, 02:53:17 am »
// broken glass ...  :)

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Button1Click(Sender: TObject);
  2.  Begin
  3.   TextOnPic(Image1, Memo1.Text, clWhite);
  4.   Image2.BringToFront; // broken glass :-)
  5.  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:
 :D 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...  :P

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...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Memo And Overlaid Image
« Reply #8 on: September 03, 2017, 02:57:51 am »
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. :P

B

Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #9 on: September 03, 2017, 03:03:09 am »
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.....  :P
« Last Edit: September 03, 2017, 03:11:54 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Memo And Overlaid Image
« Reply #10 on: September 03, 2017, 03:27:17 am »
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 :P just kidding I don't do much pascal now days.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Memo And Overlaid Image
« Reply #11 on: September 03, 2017, 03:43:55 am »
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][+][-]
  1.   Memo1.PaintTo(FalseMemoImage1.Canvas, 0, 0);
  2.   Memo1.Visible:=false;
  3.   FalseMemoImage1.BringToFront;
  4.   BrokenImage1.BringToFront;
  5.  

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
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #12 on: September 03, 2017, 05:05:25 am »
Quote
I 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][+][-]
  1. well you overshoot as expected. ...
To scroll a Label is the easiest way that I know... is it necessary ... no... it's easy !!!  :P
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Memo And Overlaid Image
« Reply #13 on: September 03, 2017, 05:21:02 am »
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
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Memo And Overlaid Image
« Reply #14 on: September 03, 2017, 07:06:57 am »
Quote
That is the trouble when bombarded with solution code - where do you start? Which one?
:D 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][+][-]
  1. UNIT Unit1;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, LCLType, ExtCtrls, StdCtrls, Types;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Label1: TLabel;
  12.  
  13.    Procedure FormCreate         (Sender: TObject);
  14.    Procedure FormKeyDown        (Sender: TObject; Var Key: Word;
  15.                                  Shift : TShiftState);
  16.    Procedure FormMouseWheelUp   (Sender: TObject; Shift: TShiftState;
  17.                                  MousePos: TPoint; Var Handled: Boolean);
  18.    Procedure FormMouseWheelDown (Sender: TObject; Shift: TShiftState;
  19.                                  MousePos: TPoint; Var Handled: Boolean);
  20.    Procedure ScrollUp           (cSpeed: Cardinal);
  21.    Procedure ScrollDown         (cSpeed: Cardinal);
  22.  
  23.     PRIVATE
  24.      iFontHeight: Integer;
  25.   End;
  26.  
  27.  VAR
  28.   Form1: TForm1;
  29.  
  30. Implementation
  31.  {$R *.LFM}
  32.  
  33.  
  34. Procedure TForm1.FormCreate(Sender: TObject);
  35.   Var
  36.    str: String;
  37.    i  : Integer;
  38.  Begin
  39.   DoubleBuffered:= True;
  40.   KeyPreview    := True;
  41.  
  42.   For i:= 1 To 500
  43.   Do str:= str+'Hello World Hello Hello Hello'+IntToStr(i)+sLineBreak;
  44.  
  45.   Label1.Caption:= str+'END of TEXT';
  46.   Label1.SetBounds(0, 0, ClientWidth, ClientHeight);
  47.  
  48.   iFontHeight:= Label1.Canvas.TextHeight('HITMqQiyYöÖ');
  49.  End;
  50.  
  51.  
  52. Procedure TForm1.ScrollUp(cSpeed: Cardinal);
  53.   Var
  54.    c: Cardinal;
  55.  Begin
  56.   For c:= 0 To cSpeed
  57.   Do
  58.    Begin
  59.     If Label1.Top >= 0 Then Exit;
  60.     Label1.Top:= Label1.Top + iFontHeight;
  61.    End;
  62.  End;
  63.  
  64.  
  65. Procedure TForm1.ScrollDown(cSpeed: Cardinal);
  66.   Var
  67.    c: Cardinal;
  68.  Begin
  69.   For c:= 0 To cSpeed
  70.   Do
  71.    Begin
  72.     If Label1.Top <= ClientHeight - Label1.Height Then Exit;
  73.     Label1.Top:= Label1.Top - iFontHeight;
  74.    End;
  75.  End;
  76.  
  77.  
  78. Procedure TForm1.FormKeyDown(
  79.            Sender: TObject; Var Key: Word; Shift: TShiftState);
  80.  Begin
  81.   If Not (ssCTRL In Shift)
  82.   Then
  83.    Begin
  84.     If Key = VK_UP
  85.     Then ScrollUp(1);
  86.  
  87.     If Key = VK_DOWN
  88.     Then ScrollDown(1);
  89.    End;
  90.  
  91.   If (ssCtrl In Shift)
  92.   Then
  93.    Begin
  94.     If Key = VK_UP
  95.     Then ScrollUp(10);
  96.  
  97.     If Key = VK_DOWN
  98.     Then ScrollDown(10);
  99.    End;
  100.  End;
  101.  
  102.  
  103. Procedure TForm1.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  104.                                   MousePos: TPoint; Var Handled: Boolean);
  105.   Var
  106.    Key: Word;
  107.  Begin
  108.   Key:= VK_UP;
  109.   FormKeyDown(Self, Key, Shift);
  110.  End;
  111.  
  112.  
  113. Procedure TForm1.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  114.                                     MousePos: TPoint; Var Handled: Boolean);
  115.   Var
  116.    Key: Word;
  117.  Begin
  118.   Key:= VK_DOWN;
  119.   FormKeyDown(Self, Key, Shift);
  120.  End;
  121.  
  122. 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...
« Last Edit: September 03, 2017, 09:30:25 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

 

TinyPortal © 2005-2018