Recent

Author Topic: Drawing on TEdit canvas  (Read 9125 times)

Mando

  • Full Member
  • ***
  • Posts: 181
Drawing on TEdit canvas
« on: March 30, 2015, 12:03:26 pm »
Hi.

I want to do a TEdit descendant that be able to draw on its canvas.

I tried WM_PAINT message but doesn't work. The message only fires when parent form redraws.

I want to achieve is that when the control text is empty, displays a text indicating what the usiario should write .

For example:
A Tedit used to introduce a user, must display " User"
another to enter the password , you must show "Password" when the text is empty.

Any idea how to achieve it ?

regards
« Last Edit: March 30, 2015, 12:06:12 pm by Mando »

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Drawing on TEdit canvas
« Reply #1 on: March 30, 2015, 12:33:20 pm »
That is I want:


zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Drawing on TEdit canvas
« Reply #2 on: March 30, 2015, 01:03:23 pm »
You can achieve that without painting. Look how it is done in TreeViewEditFilter (or similar name in IDE ..... eg for OI).

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Drawing on TEdit canvas
« Reply #3 on: March 30, 2015, 01:21:56 pm »
Hi, zeljko:

Thanks for your answer.

But I need to draw some glyps also.

regards
« Last Edit: March 30, 2015, 01:31:31 pm by Mando »

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Drawing on TEdit canvas
« Reply #4 on: March 30, 2015, 01:34:13 pm »
Ah, I've answered via phone, so that's why it wasn't bull eye hit. Now I see image at the left of text.
Thought that you need only grayed text. With qtlcl it can be achieved , but don't know how to do that under win32. Under qt you can add child control (eg. flat TBitBtn at the left + glyph).

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Drawing on TEdit canvas
« Reply #5 on: March 30, 2015, 02:15:42 pm »
You could try to use a TControlCanvas.

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Drawing on TEdit canvas
« Reply #6 on: March 30, 2015, 04:59:34 pm »
There is a feature request in the bugtracker for TextHint support.
I tried to implement it, but got stuck with Z-order problems on GTK2.

Bart

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Drawing on TEdit canvas
« Reply #7 on: March 30, 2015, 08:01:56 pm »
There is a feature request in the bugtracker for TextHint support.
I tried to implement it, but got stuck with Z-order problems on GTK2.

It is problematic even with pure gtk2 application. In gtk3 there's possibility to have an image inside GtkEdit (stupid, they can set it up as container for any gtkwidget eg. gtkbutton....)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Drawing on TEdit canvas
« Reply #8 on: March 30, 2015, 08:25:05 pm »
I wonder if this non-composting approach works for you.

(composting approach would be adding TLabel and TImage to TEdit instead of painting them)

rvk

  • Hero Member
  • *****
  • Posts: 6162
Re: Drawing on TEdit canvas
« Reply #9 on: March 30, 2015, 08:36:10 pm »
There is mention here that when the control has focus but empty the grey hint shouldn't be displayed. Is that not inconvenient? When I create a login dialog and the first control (Username) has focus the user can't see he has to type the username. Better would be to just keep showing the grey hint and only remove it when the user starts typing.

Am I alone in thinking that?
How does this work in Delphi?
(I know some DB controls have a NullText which keep showing until changed regardless of focus)

Code: [Select]
if (text='') { and not Focused } then begin

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Drawing on TEdit canvas
« Reply #10 on: March 30, 2015, 08:47:54 pm »
Am I alone in thinking that?
You're probably right. Just remove the code.


skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Drawing on TEdit canvas
« Reply #11 on: March 30, 2015, 09:22:31 pm »
now this one looks eye-candy on windows.
« Last Edit: March 30, 2015, 09:24:05 pm by skalogryz »

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Drawing on TEdit canvas
« Reply #12 on: March 31, 2015, 11:25:19 am »
Thanks to all, specially to skalogryz.

All I needed to change in my control was the message WM_PAINT by LM_PAINT.


regards

McClane

  • New Member
  • *
  • Posts: 44
Re: Drawing on TEdit canvas
« Reply #13 on: August 13, 2019, 06:45:47 pm »
TestMando.zip works on windows but not on linux. Is there some another way to make it work?
Thanks in advance.

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: Drawing on TEdit canvas
« Reply #14 on: August 13, 2019, 11:02:20 pm »
Is there some another way to make it work?
Example attached (tested on Windows only).
Advantage - only standard components, no complex code.
Disadvantage - the active edit field is not highlighted by the border color.

 

TinyPortal © 2005-2018