2010-11-23 29 views
2

Je tente de mettre en forme du texte dans richTextBox, quelque chose comme dans le chat Skype.Mise en forme de texte dans RichtextBox WPF

1.column-"Nick"   2.column-"Text of Messange"    3.column-"DateTime" 

Je veux alling 1. colonne max à gauche et 3. colonne max à droite.

Quelle est la meilleure façon de le faire? J'utilise WPF.

+0

Pourquoi utilisez-vous un seul RichTextBox (au lieu de trois (Rich) TextBlocks)? – Jens

+0

Je pense que ce n'est pas une bonne solution, par exemple si vous avez plein de richtextbox, vous devez faire défiler 3 richtetbox, aussi vous avez aussi des problèmes avec la hauteur de la ligne dans richtextboxes .... –

Répondre

1

Ma solution:

solution simple est de créer table objet et ajouter des blocs de richtextbox, somothing comme ceci:

 var tab = new Table(); 

     var gridLenghtConvertor = new GridLengthConverter(); 

     tab.Columns.Add(new TableColumn() { Name = "colNick", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") }); 
     tab.Columns.Add(new TableColumn { Name = "colMsg", Width = (GridLength)gridLenghtConvertor.ConvertFromString("5*") }); 
     tab.Columns.Add(new TableColumn() { Name = "colDt", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") }); 

     tab.RowGroups.Add(new TableRowGroup()); 
     tab.RowGroups[0].Rows.Add(new TableRow()); 

     var tabRow = tab.RowGroups[0].Rows[0]; 


     tabRow.Cells.Add(new TableCell(new Paragraph(new Run(rpMsg.Nick))) { TextAlignment = TextAlignment.Left }); 

     tabRow.Cells.Add(new TableCell(ConvertToRpWithEmoticons(rpMsg.RpText))); 

     tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Cas"))) { TextAlignment = TextAlignment.Right }); 

     RtbConversation.Document.Blocks.Add(tab);