How to customize a control?

Hi everyone!

I hope you are all fine.

I want to customize a DesktopTextField.
Simple:

a behavior “required”
and a red border that turn red if is required

only this.

how can i create this new control?

I did it inside a container, but it’s not practical. is there another way?

but it’s not practical.

what is your issue?

typically you create a container control as template and use it (drop into window) where you need it.
you set the anchors in the template too.

you can use a property or computed property, computed is better because of this events.

you can use the paint event for border drawing and use .Refresh if required boolean change.

this required you enable here to see it in the inspector.

Why does it need to be a property of the control? You mentioned in your other thread that the fields that are required vary by access control level. Make and store your own array of controls that are required for the specific user. It would be way easier.

Yes. Of course it would be easier. I’m challenging myself to learn more OOP with Xojo

on textfield?

i spoke about container control.
the text box have a background, maybe you can use other color to indicate required input.
or make a label with * or bold text.

how it looks with a container control as example

1 Like

Depending on your needs, you don’t have to use Container control, you can use Subclassing. There are plenty of videos on that.

1 Like

in window.Paint event, around the textfield…

3 Likes

Here’s a small Demo Project showing a Container Solution including a “Required” Property.
CustomizedTextField Demo.zip (6.2 KB)
Bildschirmfoto-1

3 Likes

after looking your example, i tried to do this way:

this is perfect for me, but i cant implement “graphics” there…

What are you trying to do?
Have the red rectangle if it is empty and if something is there remove the red rectangle?
You need to edit the container class on the example.

about sub classed TextField

try to make a method that give you the border color based on the flag and text size.
add a method PaintStatus(g as graphics)
add a interface
any change that effect the border call Refresh immediately false to the window.
in the windows paint event use for each at controls with variable of interface type
call this PaintStatus in yout class object with argument g from the window paint event.

this works only if the window is the parent from textbox and the input does not part of a frame.

instead of red rectangle, maybe you could link a other object/control/icon as required indicator and just make it visible or not via user defined event.

i don’t want to use containers, is it possible to do directly on textfield?

TextField does not offer a Paint event.