There is a WinForm application that reads an rtf file and displays it in richtextbox. It is necessary to insert text fields in richtextbox (analogue input type = text in html). Tell me how to do it?

  • If you needed html features in RichTextBox, can you just use html instead of rtf? I have the impression that rtf is a very outdated format, which is practically not supported. - Astronavigator
  • @Astronavigator is old! = Obsolete. Yes, it is used much less frequently than, for example, OOXML or ODF, but there are tools for reading and creating RTF in almost any OS by default, unlike other formats with markup, and in some cases this format is more than enough for simple formatting. - rdorn

1 answer 1

The RichTextBox class in .Net WinForms is a wrapper over the control from WinAPI. Nothing outsider you push into it, at least from .NET

You can of course forcibly for Textbox or Button specify Control.Parent = myRichTextBox; however you will not get the expected result. The control will of course be added inside the RichTextBox , BUT it will be added inside the container that wraps the present control and will block the text placed inside and will not follow the scroll, in this case the RichTextBox will behave like a normal Panel in the background of which the full size is placed RichTextBox , and on the front all other controls.

I do not know how things are in WPF, there seems to be no WinAPI binding, and there is a control for working with RTF, and it is even called, but working with it is somewhat more difficult than in WinForms, and I very much doubt that your use case is found Often, MS should consider the implementation of such functionality necessary.

If you need to use RichTextBox , you can use this technique - add where you need to enter something unique text into the text that the user probably will not appear in the text "by chance", something like {N:type} , enter values through the usual TexBox and TexBox tags at the end of the input from the user (N is the tag number, type is the type, for example, the entered number can be represented by the corresponding numeral, this is only a possible option).

Otherwise, it is worth once again to think about the task and the possibility of solving it in some other ways and means.

  • Found component DevExpress richedit. It perceives both docx and rtf. According to the description, it is possible to place text fields there. Has anyone worked with this component? Will he go for my purposes? - Yury
  • @Yury at DevExpress seems to have its own and technical support, it’s rather a question for them and, well, to dig deeper in the docks - rdorn
  • thank! I will pick docks - Yury