PDA

View Full Version : richtextbox and delete/backspace


Hobbs
10-24-2009, 12:18 AM
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.

denisT
10-24-2009, 04:50 PM
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.

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?

Hobbs
10-26-2009, 04:10 PM
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

denisT
10-26-2009, 06:55 PM
When you highlight all the text, and then hit delete or backspace, does it delete all the text, or just one character?


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,\nParticularly large and wide,\nThat did not fall upon the floor,\nAnd always on the buttered side.\n"

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

Hobbs
10-26-2009, 08:07 PM
You are correct, i was calling a function that i forgot about that was setting the selection length to zero. Thanks for confirming.

CGTalk Moderation
10-26-2009, 08:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.