How to create a shape acting like a textbox?
Please refer this control http://www.charlespetzold.com/blog/2009/10/Using-Text-Outlines-in-Silverlight.html The formattedtext control is a shape which helps to generate the shape of the text with proper geometry. I would like to make this control act like a text box with cursors and features like typing in from keyboard. Right now I use an invisible text box with a formattedtext control to act like that. But the cursor position always creates a problem when the size of the text is not equal to the size of the rendered text as shape.
Can anyone please show the way to achieve开发者_如何学JAVA this.
Well, I built a syntax highlighting textbox using the method you describes. Actually, at first I wanted to rebuilt everything too, but I thought : I have to build the caret fonctionnalities, the selection brush, manage a lot of different events, like selection with mouse or keyboard, deletion, Copy/Cut/Paste, etc etc...
That's a LOT of work, and windows users are used to select text in textboxes for instance, so this complex implementation cannot be left unimplemented. We must follow some Microsoft guidance on how a textbox must feel.
Actually, I think that building a new textbox from scratch is not the way to go. I suggest you to continue on your current method. If you have different fonts in the same textbox, use a RichTextBox, and handle the font changes in the textbox as well as in the formatted text.
Also, a good think to implement is to only draw the visible text with the formattedtext (but only if the user can write several hundreds of text lines).
精彩评论