Click here to Skip to main content
16,006,001 members
Home / Discussions / C#
   

C#

 
QuestionRe: windows application?? Pin
skyeddie20-Jun-06 21:55
skyeddie20-Jun-06 21:55 
AnswerRe: windows application Pin
KSCsoft20-Jun-06 20:19
KSCsoft20-Jun-06 20:19 
QuestionListView Paint Events Pin
Tyrus18220-Jun-06 16:21
Tyrus18220-Jun-06 16:21 
AnswerRe: ListView Paint Events Pin
led mike20-Jun-06 19:37
led mike20-Jun-06 19:37 
QuestionSQL Update isn't working, not sure how to fix it. Pin
PyroManiak20-Jun-06 15:18
PyroManiak20-Jun-06 15:18 
AnswerRe: SQL Update isn't working, not sure how to fix it. Pin
PyroManiak21-Jun-06 8:33
PyroManiak21-Jun-06 8:33 
QuestionHow can I format a richTextBox? Pin
AngryC20-Jun-06 10:49
AngryC20-Jun-06 10:49 
AnswerRe: How can I format a richTextBox? [modified] Pin
mikanu20-Jun-06 11:46
mikanu20-Jun-06 11:46 
Well, if I understand correctly what you're trying to do should be as easy as parsing the text in the richTextBox control and looking for the <b> and <i> tags. The easiest (not the most efficient) way to do this is to do a two-pass parse of the text. First for the BOLD tags and second for the ITALIC text.

Whenever you run into an open BOLD tag, increment boldCount variable and store the position. Then remove the tag from the text. Whenever you run into a close BOLD tag, decrement boldCount, and remove the colsing tag from the text. When boldCount = 0, select the text starting at the recorded position and then set it's bold property to TRUE. Keep going until the end of the text.

Repeat for the ITALIC tags.

Here is an example that does bold tags. Modifying this code to do italic text is trivial so it wasn't included here.. Hope this helps and don't forget to visit digitalGetto

private void ParseBoldText(RichTextBox tb)
{
    int boldCount = 0;
    int lastBoldStartPosition = 0;
    int currentPosition = 0;

    while (currentPosition < tb.Text.Length - 3)
    {
        if (tb.Text.Substring(currentPosition, 3) == "<b>")
        {
            if(boldCount == 0)
                lastBoldStartPosition = currentPosition;
            boldCount++;
        }
        if (tb.Text.Substring(currentPosition, 4) == "</b>")
        {
            boldCount--;
            if (boldCount == 0)
            {
                tb.Select(lastBoldStartPosition + 3, currentPosition - lastBoldStartPosition - 3);
                tb.SelectionFont = new Font(tb.SelectionFont.FontFamily, tb.SelectionFont.Size, tb.SelectionFont.Style | FontStyle.Bold);
            }
        }
        currentPosition += 1;
    }

    //clean the <B> tags, carefulf to use the RTF property instead of TEXT property !!!!
    tb.Rtf = tb.Rtf.Replace("<b>", "");
    tb.Rtf = tb.Rtf.Replace("</b>", "");
}


----
www.digitalGetto.com

-- modified at 18:07 Tuesday 20th June, 2006
GeneralRe: How can I format a richTextBox? [modified] Pin
AngryC20-Jun-06 13:26
AngryC20-Jun-06 13:26 
GeneralRe: How can I format a richTextBox? Pin
AngryC20-Jun-06 13:28
AngryC20-Jun-06 13:28 
GeneralRe: How can I format a richTextBox? Pin
mikanu21-Jun-06 6:27
mikanu21-Jun-06 6:27 
QuestionC# Application: How to associate an icon Pin
kirkangel20-Jun-06 9:33
kirkangel20-Jun-06 9:33 
AnswerRe: C# Application: How to associate an icon Pin
Judah Gabriel Himango20-Jun-06 9:36
sponsorJudah Gabriel Himango20-Jun-06 9:36 
JokeRe: C# Application: How to associate an icon Pin
kirkangel27-Jun-06 10:23
kirkangel27-Jun-06 10:23 
QuestionProblem using EntLib DAAB for .NET 2.0 Pin
supD20-Jun-06 9:27
supD20-Jun-06 9:27 
AnswerRe: Problem using EntLib DAAB for .NET 2.0 Pin
Judah Gabriel Himango20-Jun-06 9:35
sponsorJudah Gabriel Himango20-Jun-06 9:35 
AnswerRe: Problem using EntLib DAAB for .NET 2.0 Pin
Blue(Shanghai)20-Jun-06 16:31
Blue(Shanghai)20-Jun-06 16:31 
QuestionDatagrid showing bogus data when page loads Pin
leckey20-Jun-06 8:36
leckey20-Jun-06 8:36 
AnswerRe: Datagrid showing bogus data when page loads Pin
freshonlineMax20-Jun-06 19:20
freshonlineMax20-Jun-06 19:20 
Questionquestion about MS spell check Pin
likefood20-Jun-06 8:34
likefood20-Jun-06 8:34 
AnswerRe: question about MS spell check Pin
likefood20-Jun-06 8:38
likefood20-Jun-06 8:38 
QuestionGDI : how does paint event work? Pin
User 309585920-Jun-06 8:13
User 309585920-Jun-06 8:13 
AnswerRe: GDI : how does paint event work? Pin
Johnny Hooyberghs20-Jun-06 8:38
Johnny Hooyberghs20-Jun-06 8:38 
GeneralRe: GDI : how does paint event work? Pin
User 309585920-Jun-06 8:44
User 309585920-Jun-06 8:44 
Questioncatching exceptions and posting them in a dialog Pin
Johnny Hooyberghs20-Jun-06 7:41
Johnny Hooyberghs20-Jun-06 7:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.