Eto: Add text properties and events to ComboBox

Created on 19 May 2020  ·  7Comments  ·  Source: picoe/Eto

I need to change the case of the key pressed as it is typed.

The key press itself is trivial to catch with OnKeyDown but it is not apparent how to find the cursor position in the text in order to replace the character typed.

The event OnTextChanged is called too late, when the text has already been changed.

All 7 comments

Try the TextInput event, which you can cancel. The cursor position of a TextBox or TextArea can be easily determined using TextBox.Selection.

This is consequently how the MaskedTextBox works, which is another option to do what you are looking by implementing IMaskedTextProvider that translates the text how you want. The VariableMaskedTextProvider helps out with the base implementation which you can tweak to your requirements:

```c#
class UpperCaseProvider : VariableMaskedTextProvider
{
public override bool Insert(char character, ref int position)
{
return base.Insert(char.ToUpper(character), ref position);
}

public override bool Replace(char character, ref int position)
{
    base.Replace(char.ToUpper(character), ref position);
}

}

Then to use it:
```c#
new MaskedTextBox(new UpperCaseProvider());

Hope this helps.

Will do.

I did not try because the documentation says that there are limitations to TextInput in iOS.

Darn it.

I am trying to use this in a ComboBox but I cannot cast the ControlObject to Eto.Wpf.Forms.Controls.EtoComboBox (to access its TextBox) which, in any case, begs the question of how to do it in a cross-platform manner.

Hm, yeah a ComboBox does not have all of the text events/properties like a TextBox does. They should probably be added.

If you're attempting to do some form of autocomplete, one thing that has worked for me is to use a TextBox and show a borderless form in the correct position. This also gives you more flexibility in the items shown and how they are shown. It does end up being a bit of work though.

Will do. Thanks.

Hey @LaraSQP, I'm leaving this one open to track implementing the properties/events for ComboBox.

You are right. Sorry about that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sanae6 picture Sanae6  ·  4Comments

katatunix picture katatunix  ·  12Comments

azunyuuuuuuu picture azunyuuuuuuu  ·  23Comments

ArsenShnurkov picture ArsenShnurkov  ·  17Comments

Serg-Norseman picture Serg-Norseman  ·  5Comments