Forum > LCL

Add Caret to a component

(1/3) > >>

McClane:
Hello, I want to make my own component and I don't know how to add a caret to it.
Can you guide me please?
I've been looking for TCaret but I couldn't find it.

Thanks in advance and have a nice day.

I want to start with this line of code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TBEdit = class(TWinControl)

Martin_fr:
There is on class, but there are functions.

CreateCaret, SetCaretPos
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createcaret
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcaretpos
and more.

The LCL offers those for all the WidgetSets.

An Example can be found in package SynEdit, in the unit SynEditPointClasses: TSynEditScreenCaretPainterSystem


There are certain rules how to handle it for paint and scroll events.

Also, there is only ONE caret for the ENTIRE application. If any other Control (including normal TEdit/TMemo) show the caret, it will disappear from your component.

You can draw your own caret. But then you must see to it, that it takes settings like blink frequency in account. Or stops blinking as the system caret would do....

McClane:
Hi Martin_fr, thank you so much for your reply.
I've discovered CreateCaret(handle) but the only way I can see it, it's on the paint method and it doesn't blink.
I'll keep investigating.
I have a new question and I don't know if i have to create a new post.
How can I print text on a handle.
Thanks again and have a nice day.

Martin_fr:
There are calls to create it, set the size, set the pos, show/hide it.....

The paint method may show/hide it. In SynEdit iirc it's created in OnFocus.

On modern Windows, the caret only blinks a few times, and if nothing is typed, then it stops blinking. On other OS that may be different.

A WinControl has a canvas, that you can print to. IIRC it has methods to do that.

There is also "TextOut" / "TextOutEx"

E.g. unit SynEditTextDrawer.

winni:

--- Quote from: Martin_fr on November 18, 2021, 08:33:17 pm ---
A WinControl has a canvas, that you can print to. IIRC it has methods to do that.

--- End quote ---

Hi!

A WinControl owns no canvas!
The reason for a lot of hacks.

Winni

Navigation

[0] Message Index

[#] Next page

Go to full version