locked
RichEditBox: How to set the line spacing in percent?

    Question

  • I am using the RichEditBox control in my Windows 8.1 application but whenever I set the line spacing in percent the app crashes throwing an InvalidArgumentException.

    ITextParagraphFormat^ format = richEditBox->Document->GetDefaultParagraphFormat();
    format->SetLineSpacing(LineSpacingRule::Percent, 120);
    richEditBox->Document->SetDefaultParagraphFormat(format);

    However something like this works perfectly fine.

    ITextParagraphFormat^ format = richEditBox->Document->GetDefaultParagraphFormat();
    format->SetLineSpacing(LineSpacingRule::Exactly, 120);
    richEditBox->Document->SetDefaultParagraphFormat(format)

    Does anyone know what I am doing wrong?








    Sunday, January 5, 2014 5:16 PM

Answers

  • Hi Dominik Jordan,

    RichEditBox doesn't suport LineSpacingRule::Percent. You need to use Exatly to achieve the same purpose.

    For confirm my guess( because I couldn't see the source code):

    1. I use format->LineSpacing to get the default value (0) and get the default rule(single(1)).

    auto a=format->LineSpacing;
    	auto b=format->LineSpacingRule;

    2. I think maybe the value 0 is the reason, so I set the value as below:

    format->SetLineSpacing(LineSpacingRule::Exactly, 50);
    	 a=format->LineSpacing;
    	 b=format->LineSpacingRule;

    3. I check the rule value(Exactly) and the spacing value(50).

    4. finally, I set line spacing as rule value = Percent:

    format->SetLineSpacing(LineSpacingRule::Percent, 50);

    unfortunately, The result is the same as yours.

    At last, I look at Call Stack, but from the stack trace, I only know the exception is from the SetLineSpacing function. And I couldn't go further without the source code.(Certainly, I couldn't get it)

    So, I believe, there must be some operations in this function haven't consider this situation.

    And for this, all the controls based on Windows::UI::Text::ITextParagraphFormat will give you this issue, and I have confirmed this.

    Maybe this percent value is only used by VSLMockITextPara.h .

    I hope it is helpful!

    Regards!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 6, 2014 9:43 AM
    Moderator
  • Hi Dominik,

    I confirmed Xiaoliang's guess. LineSpacingRule::Percent is not currently supported by the underlying RichEdit paragraph object.

    --Rob

    Tuesday, January 7, 2014 4:11 AM
    Owner

All replies

  • I'm not where I can check for certain, but as a guess try setting 1.2 instead of 120.
    Sunday, January 5, 2014 6:47 PM
    Owner
  • I already tried this. Things like 1.2F, 0.5, 0.1, 50, 100, or even 0. Everything results in an exception.
    Sunday, January 5, 2014 6:50 PM
  • Hi Dominik Jordan,

    RichEditBox doesn't suport LineSpacingRule::Percent. You need to use Exatly to achieve the same purpose.

    For confirm my guess( because I couldn't see the source code):

    1. I use format->LineSpacing to get the default value (0) and get the default rule(single(1)).

    auto a=format->LineSpacing;
    	auto b=format->LineSpacingRule;

    2. I think maybe the value 0 is the reason, so I set the value as below:

    format->SetLineSpacing(LineSpacingRule::Exactly, 50);
    	 a=format->LineSpacing;
    	 b=format->LineSpacingRule;

    3. I check the rule value(Exactly) and the spacing value(50).

    4. finally, I set line spacing as rule value = Percent:

    format->SetLineSpacing(LineSpacingRule::Percent, 50);

    unfortunately, The result is the same as yours.

    At last, I look at Call Stack, but from the stack trace, I only know the exception is from the SetLineSpacing function. And I couldn't go further without the source code.(Certainly, I couldn't get it)

    So, I believe, there must be some operations in this function haven't consider this situation.

    And for this, all the controls based on Windows::UI::Text::ITextParagraphFormat will give you this issue, and I have confirmed this.

    Maybe this percent value is only used by VSLMockITextPara.h .

    I hope it is helpful!

    Regards!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 6, 2014 9:43 AM
    Moderator
  • Thank you very much. Now I'm certain that it is not a problem in my code but something like an undefined behavior. I will use LineSpacingRule::Exactly, Multiple or just OneAndHalf.
    Monday, January 6, 2014 9:57 AM
  • Hi Dominik,

    I confirmed Xiaoliang's guess. LineSpacingRule::Percent is not currently supported by the underlying RichEdit paragraph object.

    --Rob

    Tuesday, January 7, 2014 4:11 AM
    Owner