2009-07-22 30 views
0

コンテンツがパターンに合致していると仮定して、テキストボックス(またはリッチテキストボックス)の内容をコンテンツに基づいてフォーマットするライブラリがありますか? winform(またはWPF)を好むとはいえ、これがウェブ世界とwinformの両方で可能だったらいいと思います。テキストボックスの書式設定

+0

可能な重複:http://stackoverflow.com/questions/1087735/a-textbox-richtextbox-that-has-syntax-highlighting-c –

答えて

1

プログラムでテキストを選択してから、SelectionColorプロパティを設定するだけです。もちろん、選択するテキストを特定する正規表現を書く必要がありますが、後で色付けするのは簡単です。

Oh yeah;これは、TextBoxの場合のみ機能し、RichTextBox(明らかに)は機能しません。

1

テキストを選択して色を設定するだけで、リッチテキストボックスでこれを行うことができます。

はしかし、あなたがリサイズを述べているので、あなたはSyntaxEditor by ActiProで見たいと思うかもしれません、例えば

...そこに、より精巧なライブラリがあります。

1

これは少し必要です。 最初の文字から第10文字の を選択するか、またはリッチテキストボックス の全長を選択して、選択した色を変更します。 重要なことは、いったん選択を行うと、RichTextBox全体ではなく選択肢が変更されることです。 フォントを太字に変更することができます。 太字は少しばかりです。

'select the first character 
rtbRichTextBox.SelectionStart = 0 
'Select the length forward as far as you need to 
rtbRichTextBox.SelectionLength = 10 'Len(rtbRichTextBox.Text) 

' change the text color 
rtbRichTextBox.SelectionColor = Color.Blue 

' make a highlight color over the text 
'rtbRichTextBox.SelectionBackColor = Color.Yellow 

Dim newFontStyle As System.Drawing.FontStyle 

If rtbRichTextBox.SelectionFont IsNot Nothing Then 
    newFontStyle = FontStyle.Bold 
    rtbRichTextBox.SelectionFont = New Font(MyObj_Font_Arial.FontFamily, _ 
              MyObj_Font_Arial.Size, _ 
              newFontStyle) 
end if 

'a more straight forward bold would be to change the font. 
Dim MyObjectArialFont As New Font("Arial", 6.5, FontStyle.Bold) 
rtbRichTextBox.SelectionFont = MyObjectArialFont