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 DelegateChangeF ont();
private DelegateChangeF ont m_ChangeFontD;
private void Form1_Load(obje ct sender, EventArgs e)
{
this.m_ChangeFo ntD = new DelegateChangeF ont(ChangeFont) ;
}
private void button1_Click(o bject sender, EventArgs e)
{
m_ChangeFontD() ;
}
private void button2_Click(o bject sender, EventArgs e)
{
Thread t = new Thread(ChangeFo nt);
t.Start();
}
private void ChangeFont()
{
if (InvokeRequired )
{
Invoke(m_Change FontD, null);
return;
}
bool wasProtected = false;
string s = richTextBox1.Se lectedText;
int selectionStart = richTextBox1.Se lectionStart;
int selectionLength = richTextBox1.Se lectionLength;
FontDialog fd = new FontDialog();
fd.ShowColor = true;
fd.Color = richTextBox1.Se lectionColor;
Font font = richTextBox1.Se lectionFont;
fd.Font = font;
if (fd.ShowDialog( ) == DialogResult.OK )
{
richTextBox1.Fo cus();
//richTextBox1.Se lectionStart = selectionStart;
//richTextBox1.Se lectionLength = selectionLength ;
richTextBox1.Se lect(selectionS tart, selectionLength );
//regain selection
s = richTextBox1.Se lectedText;
if (richTextBox1.S electionProtect ed)
{
wasProtected = true;
richTextBox1.Se lectionProtecte d = false; // so the font can change
}
richTextBox1.Se lectionFont = fd.Font;
richTextBox1.Se lectionColor = fd.Color;
richTextBox1.Se lectionProtecte d = wasProtected;
s = richTextBox1.Se lectedText;
System.Diagnost ics.Debug.Print ("SelectedTe xt after font '" + s + "'");
}
richTextBox1.Se lect(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-****@online.mic rosoft.com, 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:
ms****@microsof t.com.
=============== =============== =============== =====
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.