C# Extended Text Editor

F

foolsbar

Hi,

Does anyone know how I can go about the following? I want to write a
custom control that will probably extend from the textbox control that
enables the user to insert some pre-defined fields into the text
whenever they right-click at the selected point. I know you can
determine the co-ordinates of a DataGridView using the HitTestInfo
method, but is there a similar method for the textbox control?

I would like it so that the field is somehow "protected" - i.e. the
user can't edit the information within the field, they can only delete
the field. Does that make sense?

If there are any articles, code sources etc that I can be directed to,
it would be much appreciated.

Many thanks

Andy
 
N

n4ixt

The text box has a SelectionStart property, if no text is selected it will
tell you the current position of the cursor within the text box.

You could of course use the mouse up event to detect a right click, then pop
up a menu.

Protecting the field gets a lot trickier. You'll have to constantly monitor
the cursors current position and examine the text on / around that position.
If it's one of your predefined tags, you'd have to set the Selection Length
to the length of the tag, or auto move the selectionstart to just past the
tag. Also you'd have to intercept the keypress event to make sure user
didn't type something while in the field. Either that or always move the
cursor to either side of the field, never let him land right in a tag.

Lots of events you'd have to code up, but could be done if you had to roll
your own. I bet in a long week you could have something working. Can't say
I've seen an off the shelf package though that will do what you ask.

Robert
http://n4ixt.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top