This is a migrated thread and some comments may be shown as answers.

Custom Style definition

3 Answers 123 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Marcin asked on 29 Sep 2016, 06:33 PM

I've 2 questions:

First one:

I've a problem with custom Style definition. I want to edit some of built-in styles. At this moment I've got this code:

StyleDefinition h1 = this.radRichTextEditor1.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1));
h1.SpanProperties.FontSize = ConstDocumentationParams.fontSizeH1;
h1.SpanProperties.ForeColor = System.Drawing.ColorTranslator.FromHtml(ConstDocumentationParams.colorH1);
h1.SpanProperties.FontStyle = ConstDocumentationParams.typeH1;
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily(ConstDocumentationParams.fontFamily);

 

Everything works fine until I select text and click the heading edited by me. Text changes to old style, not new. How can I fix this problem?

 

Second one:

How can I insert programmatically some element whitch will be generated to html tag: "<h1>","<h2>" etc.

 

Best regards

Marcin

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 30 Sep 2016, 11:26 AM
Hi Marcin,

Thank you for writing.

1. I was not able to reproduce this. This is why I have attached my test project. Could you please check it and let me know what I need to change in order to reproduce the undesired behavior?

2. You can specify the paragraph's StyleName before inserting it. For example:
Section section = new Section();
Paragraph paragraph = new Paragraph();
paragraph.StyleName = RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1);
Span span = new Span("Span declared in code-behind");
paragraph.Inlines.Add(span);
section.Blocks.Add(paragraph);
radRichTextEditor1.Document.Sections.Add(section);

I am looking forward to your reply.
 
Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Marcin
Top achievements
Rank 1
answered on 30 Sep 2016, 12:18 PM

Dimitar, thank you for writing.

 

In attachments You can find what I was talking about.

My steps:

1. write some text(in style from "Heading 1"

2. select some of letters

3. click on "heading 1"

4. old style :(

 

I have version: 2016_2_608 of winforms

 

Best regards,

Marcin 

0
Dimitar
Telerik team
answered on 04 Oct 2016, 06:07 AM
Hi Marcin,

Thank you for writing.

This is considered an issue which I have logged in our Feedback Portal. I have added a vote for it on your behalf as well. You can track its progress, subscribe for status changes and add your comment to it here. I have also updated your Telerik Points.

To workaround this you need to set the styles of the linked style definition as well: 
StyleDefinition h1 = this.radRichTextEditor1.Document.StyleRepository.GetValueOrNull(RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(1));
h1.SpanProperties.FontSize = 33;
h1.SpanProperties.ForeColor = System.Drawing.ColorTranslator.FromHtml("#e83737");
  
StyleDefinition h1Char = h1.LinkedStyle;
  
h1.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1.SpanProperties.FontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily("Segoe Script");
  
h1Char.SpanProperties.FontWeight = Telerik.WinControls.RichTextEditor.UI.FontWeights.Normal;
h1Char.SpanProperties.FontFamily = new Telerik.WinControls.RichTextEditor.UI.FontFamily("Segoe Script");
  
h1Char.SpanProperties.FontSize = 33;
h1Char.SpanProperties.ForeColor = System.Drawing.ColorTranslator.FromHtml("#e83737");

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
RichTextEditor
Asked by
Marcin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Marcin
Top achievements
Rank 1
Share this question
or