Notifications
Clear all

[Closed] richtextbox and delete/backspace

I’m working on a richtextbox for .net, and i’d like to have it when you hit backspace or delete, if you have text selected, it clears it.

I have the command to clear the text, i have the command to capture if you hit backspace or delete.

The problem i have is that when the user hits delete or backspace, the selection gets lost, and it only deletes one letter for delete, or nothing for backspace.

Basically in the keydown method after hitting delete, if you ask print out the selection length, it prints out zero.

Is there something i’m missing, or has someone else come across this problem?

Thanks.

4 Replies
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

It sounds a little strange for me. RichTextBox has “delete by hit DEL or BACKSPACE” functionality. You don’t need to do anything special. It’s a default behavior for the control.

Do you want to overwrite it for any reason?

When you highlight all the text, and then hit delete or backspace, does it delete all the text, or just one character?

For me, for some reason, it is only deleting one character. I would like it to delete the selected text.

My buddy told me to look into the keypreview call, but if it works for you, where you select a bunch of text and press delete, and it clears the selection, then i’m doing something wrong somewhere.

thanks

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

it has to delete all selected text by clicking “del” or “backspace”, add CTRL+X…

if it doesn’t work for you probably something is wrong with “RichTextBox” settings.


try(destroydialog rich_rol) catch()
rollout rich_rol "test RichTextBox"
(
 local rich = \
 "I never had a slice of bread,
Particularly large and wide,
That did not fall upon the floor,
And always on the buttered side.
"
 
 dotnetcontrol rtb "RichTextBox" pos:[0,0] width:200 height:200 
 on rich_rol open do
 (
  rtb.text = rich
  rtb.selectionstart = 30
  rtb.selectionlength = 29
  rtb.Focus()
 )
)
createdialog rich_rol width:200 height:200

You are correct, i was calling a function that i forgot about that was setting the selection length to zero. Thanks for confirming.