More information.
If you load the RTF directly with teh text below. Then try to make changes.
When you make a secong change the first is lost.
richTextBox1.Rtf =
@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}}
{\colortbl
;\red128\green0\blue128;\red255\green0\blue0;\red0\green128\blue128;\red0\green0\blue128;}
\viewkind4\uc1\pard\cf1\f0\fs17 Test \cf0 text %%IndexField1%% set a \cf2
form \cf3\b\i\protect\fs18 %%str_OperatorName%%\cf0\b0\i0\protect0\fs17 \cf4
activated\cf0\par
}";
"""Ji Zhou [MSFT]""" wrote:
Quote:
> Hello John,
>
> Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
> [MSFT] and I will be working on this issue with you.
>
> Based on my understanding, the issue we are now facing is, when we set the
> second set of characters' font and color in the RichTextControl, the
> previous set font and color are lost, right? Please feel free to correct me
> if I have misunderstood your issue.
>
> Your codes look very well, and I have also tested them on my side, but the
> result is same as breitak's. I cannot reproduce the issue. No matter how
> many times I set the selected text's font and color, the previous set font
> and color remains ok. I have uploaded my project in the following link, and
> would you like to download it and test it will work on your side?
>
> http://cid-c2e0d62e8a095a30.skydrive.../RichTextContr
> olFontIssue.zip
>
> For your convenience, I also post my core codes here,
>
> private String m_TextToInsert = "Default";
> private delegate void DelegateChangeFont();
> private DelegateChangeFont m_ChangeFontD;
>
> private void Form1_Load(object sender, EventArgs e)
> {
> this.m_ChangeFontD = new DelegateChangeFont(ChangeFont);
> }
>
> private void button1_Click(object sender, EventArgs e)
> {
> m_ChangeFontD();
> }
>
> private void button2_Click(object sender, EventArgs e)
> {
> Thread t = new Thread(ChangeFont);
> t.Start();
> }
>
> private void ChangeFont()
> {
> if (InvokeRequired)
> {
> Invoke(m_ChangeFontD, null);
> return;
> }
>
> bool wasProtected = false;
>
> string s = richTextBox1.SelectedText;
> int selectionStart = richTextBox1.SelectionStart;
> int selectionLength = richTextBox1.SelectionLength;
>
> FontDialog fd = new FontDialog();
> fd.ShowColor = true;
> fd.Color = richTextBox1.SelectionColor;
> Font font = richTextBox1.SelectionFont;
> fd.Font = font;
>
> if (fd.ShowDialog() == DialogResult.OK)
> {
> richTextBox1.Focus();
> //richTextBox1.SelectionStart = selectionStart;
> //richTextBox1.SelectionLength = selectionLength;
> richTextBox1.Select(selectionStart, selectionLength);
> //regain selection
> s = richTextBox1.SelectedText;
>
> if (richTextBox1.SelectionProtected)
> {
> wasProtected = true;
> richTextBox1.SelectionProtected = false; // so the font can change
> }
>
>
> richTextBox1.SelectionFont = fd.Font;
> richTextBox1.SelectionColor = fd.Color;
> richTextBox1.SelectionProtected = wasProtected;
>
> s = richTextBox1.SelectedText;
> System.Diagnostics.Debug.Print("SelectedText after font '" + s + "'");
> }
>
> richTextBox1.Select(0, 0);
> m_TextToInsert = "";
> }
>
> It works for both scenarios that I click the button1 and the button2.
> Button1 click event handle will not into the Invoke method, while button2
> click event handle does because it raise a new thread. Please let me know
> if there is any difference from your side. Then, I can try my best to do
> future research.
>
>
> Best regards,
> Ji Zhou (v-jzho@xxxxxx, remove 'online.')
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msdnmg@xxxxxx.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://support.microsoft.com/select/...tance&ln=en-us.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>