-1

I would like to have a simple TextBox or a RichTextBox with the possibility to format my text. I only need the options "bold", "italic", "underline" and the fontsize. My text input and output need to be in html format but I can't get this format from the RichTextBox. Is there a simple way to get the right format? Or is there another option that suits my needs?

fieRce
  • 13
  • 3
  • Not sure if it's one question (format text) or three (html <---> `RichtTextBox`). See [this](https://stackoverflow.com/a/5442224/1997232) or [this](https://stackoverflow.com/q/18092639/1997232) (should be more) regarding formatting. – Sinatr Aug 28 '19 at 07:14

2 Answers2

0

Since I gather you will be editing in this thing then you'd have to translate html into xaml objects and back again if you used a richtextbox.

Telerik supply a control which does this. Which would be rather expensive on it's own. Telerik controls are good and this would be a route to consider if the functionality in their other controls was useful.

You could instead use a control designed specifically for html editing.

The Smith HTML editor is a very old codeplex project but plain html will not have changed and I think the code is included.

https://archive.codeplex.com/?p=smithhtmleditor

Andy
  • 11,864
  • 2
  • 17
  • 20
  • I have the possibility to use Telerik Controls. I will try to use their control. Thank you for your response – fieRce Aug 28 '19 at 08:43
-1

I found a nice article that gives a format bar for editing fonts via font family, size, style, etc. Please see this link, where you can download the source code: https://elegantcode.com/2010/10/26/create-your-own-format-bar-for-the-wpf-richtextbox/. Also make sure to add a reference to System.Windows.Controls.Ribbon.dll. You will find it under Project->Add Reference->Framework->Assemblies in Visual Studio.

As for converting the resulting format into HTML, you can simply make strings given what UI element the user selects in the code behind's event-handling methods. So, you can make strings with <b></b> or <strong></strong> tags for bold, <i></i> tags for italics, and <u></u> tags for underline. Then for attributes like font family and font size, make strings of <style></style> tags, and include the CSS attributes font-family and font-size.

Max Voisard
  • 1,685
  • 1
  • 8
  • 18
  • Thank you for your response. With this solution the whole text will be for example bold. But I need a RichTextBox where the user can write some text bold, some italic and so on. Afterwards I need to export the whole text to a "html" string. Like "myTextanotherTextsomeText – fieRce Aug 28 '19 at 07:10
  • @fieRce I see. I'll give you an edit, make sure you take a look and see it later. – Max Voisard Aug 28 '19 at 07:29