|
Is it possible to format the text (such as bold, italics etc) at the time of entering the strings into a text control, not thru code but via the text field on the control's property page??? | | Boulderdude Friday, August 18, 2006 5:31 PM |
private void HighLightText(string text1,Color color1, bool matchWholeWord)
{
int lFoundPos;
int lFindLength;
int lOrgSelStart;
int lOrgSelLen;
int iMatchCount = 0 ;
lOrgSelStart = rtf_cvText.SelectionStart;
lOrgSelLen = rtf_cvText.Rtf.Length;
lFindLength = text1.Length;
if (matchWholeWord)
{
lFoundPos = this.rtf_cvText.Find(text1,0,lOrgSelLen,System.Windows.Forms.RichTextBoxFinds.WholeWord);
}
else
{
lFoundPos = this.rtf_cvText.Find(text1,0,lOrgSelLen,System.Windows.Forms.RichTextBoxFinds.None);
}
while (lFoundPos != -1)
{
iMatchCount = iMatchCount + 1;
rtf_cvText.SelectionStart = lFoundPos;
rtf_cvText.SelectionLength = lFindLength;
rtf_cvText.SelectionColor = color1;
if (matchWholeWord)
{
lFoundPos = rtf_cvText.Find(text1,lFoundPos + lFindLength,lOrgSelLen,System.Windows.Forms. RichTextBoxFinds.WholeWord);
}
else
{
lFoundPos = rtf_cvText.Find(text1,lFoundPos + lFindLength,lOrgSelLen,System.Windows.Forms. RichTextBoxFinds.None);
}
}
}
This hightlights words in different colours but rtf_cvText. should
rtf_cvText.SelectionFont.Bold = true; do the trick for bold.
James
| | James Knowles Friday, August 18, 2006 6:06 PM | Do you mean when some is typing in ? i.e Highlight some text and runtime and make it bold ?
James
| | James Knowles Friday, August 18, 2006 5:57 PM | Exactly. Is that possible??? I have a bunch of text that I need to enter into the text control and would like to have some in bold. | | Boulderdude Friday, August 18, 2006 6:00 PM |
private void HighLightText(string text1,Color color1, bool matchWholeWord)
{
int lFoundPos;
int lFindLength;
int lOrgSelStart;
int lOrgSelLen;
int iMatchCount = 0 ;
lOrgSelStart = rtf_cvText.SelectionStart;
lOrgSelLen = rtf_cvText.Rtf.Length;
lFindLength = text1.Length;
if (matchWholeWord)
{
lFoundPos = this.rtf_cvText.Find(text1,0,lOrgSelLen,System.Windows.Forms.RichTextBoxFinds.WholeWord);
}
else
{
lFoundPos = this.rtf_cvText.Find(text1,0,lOrgSelLen,System.Windows.Forms.RichTextBoxFinds.None);
}
while (lFoundPos != -1)
{
iMatchCount = iMatchCount + 1;
rtf_cvText.SelectionStart = lFoundPos;
rtf_cvText.SelectionLength = lFindLength;
rtf_cvText.SelectionColor = color1;
if (matchWholeWord)
{
lFoundPos = rtf_cvText.Find(text1,lFoundPos + lFindLength,lOrgSelLen,System.Windows.Forms. RichTextBoxFinds.WholeWord);
}
else
{
lFoundPos = rtf_cvText.Find(text1,lFoundPos + lFindLength,lOrgSelLen,System.Windows.Forms. RichTextBoxFinds.None);
}
}
}
This hightlights words in different colours but rtf_cvText. should
rtf_cvText.SelectionFont.Bold = true; do the trick for bold.
James
| | James Knowles Friday, August 18, 2006 6:06 PM | Thanks James. I'll try that and let you know how it goes. | | Boulderdude Friday, August 18, 2006 6:16 PM | You can probably just get away with using
rtf_cvText.SelectionFont.Bold = true; do the trick for bold.
As you will have all got the user to hightlight the text in the richtext box . The above code does a search through to highlight a word in a rich text box.
Goodluck off for a beer now ;-) Have a good weekend.
James
| | James Knowles Friday, August 18, 2006 6:19 PM |
|