Home » WPF

How to align text with in Richtextbox in Wpf

hi All

I want to align the text within a richtextbox ie align top ,align bottom ,middle align

i can align the richtextbox object but not able to align text within the richtextbox

does anyone have solution for this problem




3 Answers Found


Answer 1


have you tried VerticalContentAlignment?


Answer 2

hi hbarck

i have tried this property but it is not working

i want to change  alignment on click of button align top,center,bottom

here rtb is the richtextbox's name


privatevoid button1_Click(object sender, RoutedEventArgs e)


rtb.VerticalContentAlignment = System.Windows.




any other idea



Answer 3

Hi Amit_hamirpur,

Flow document are designed to optimize viewing and readability. Rather than being set to one predefined layout, flow documents dynamically adjust and reflow their content based on tun-time variables such as window size, device resolution, and optional user preferences.

So, we cannot set the layout of the document in the RichTextBox manually, but for the paragraph, we can set the TextAlignment property. And you can also try to set the Padding property for the RichTextBox to adjust it content.

Hope this helps.

Best regards,
Kevin Pan



How to find the Hyperlinks in the Pasted text in WPF RIchtextbox.

please give me the Solution



I want to save (and after that also to retrieve) the content of an WPF RichTextBox (text + image) to/from the database.

I found this: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/750a654e-b002-4742-8f46-609e93f6ec81 but like the author said, the solution seams not to work for text with image - the image is ignored/removed and only the formatted text is saved and after that retrieved to/from database.

Know someone a solution about this issue?

Best regards,






Hi all.

I have a richtextbox in WPF. I type some text in it using blue color and some other format. Addtional, I write text in VietNamese language.

Now I want to transfer entirely plain text, its format and encode to other WPF Richtextbox.

I try it out, but not successful.

Anybody have the better ideas.

Thanks so much.





Good day!

I'm using a wpf richtextbox control in my winform application.

I want to know how to append text in the wpf richtextbox control using a winform app button control with the formatting options I want. I want to append a bold string with a center alignment. I don't know how to do it.

Thank you


Dear all,

          I try to align text of a button to mid left, but it just show in mid center. Some buttons can be aligned to mid left. I have set the autosize to false, but it does not work. What is the problem? Please help. Thanks.


Hello everybody,

[If there is already an answer for a similar question, please redirect me to it. I need the answer fast.]


Here is what I got so far:


1) I have a VB2010 Project. The form contains the following things:

1 RichTextBox (RichTextBox1) 8 Buttons (Colors: Red,Green,Yellow,Blue,Teal,Pink,White,Black) (Button1 until Button8) 1 Button "Copy Selected Text" (Button9) 1 TextBox (TextBox1) 1 Button "Copy Finished Text to Clipboard" (Button10)


2) Here is how the program should work:

I write some text into the RichTextBox I select specific parts of the text, click one of the 8 color buttons and the selected text becomes that color I do that until all the text is randomly colored e.g: RedGreenYellowBlueTealPinkWhiteBlack I select all of the text "RedGreenYellowBlueTealPinkWhiteBlack" I press the "Copy Selected Text" Button (Button9) The selected text should become visible in the TextBox like this: ^1Red^2Green^3Yellow^4Blue^5Teal^6Pink^7White^8Black I press the "Copy Finished Text to Clipboard" (Button10) The character count (length) of the TextBox1 should not exceed 32 characters. If it does show message box. The whole TextBox1 should be copied. If the text is successfully copied, show MessageBox with "Success" else show MessageBox with "Error"

The following step gives me a terrible headache: 6

Step 6: The program should do the following:

Put a "^1" infront of all the RED colored parts in the selected text, put a "^2" infront of all the GREEN colored parts in the selected text and so on until it reaches BLACK where it should put "^8" infront of it. "RedGreenRedRedBlack" should look like this: ^1Red^2Green^1RedRed^8Black

3) This is my CODE so far:
PublicClass Form1

 PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Red
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Green
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Yellow
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Blue
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Teal
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Pink
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.White
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
 Dim Position As Int16 = 0
 Dim myColor As Color = Color.Black
 RichTextBox1.SelectionColor = myColor
 EndSubPrivateSub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
 'Step 6: No code yet !!EndSubPrivateSub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
 Dim length AsString
 length = TextBox1.Text.Length.ToString()
 If length > 32 Then
  MsgBox("Your text is too long. Steam allows only 32 characters. Shorten it and try again.")
 ElseIf length < 33 Then
  MsgBox("The text has been copied to the clipboard successfully." & vbCrLf & "You can now go to your Steam Settings and paste it into the 'Profile Name' space.", MsgBoxStyle.Information, "Success")
  MsgBox("Some error occured. The text has not been copied. Try copying it again.", MsgBoxStyle.Critical, "Critical error")

I hope somebody understands my problem and a thank you in advance for all the answers.




Hi i am looking for a way to align the buttons in my treeview so that it will look like in the same column even if it is in any level. Eg:


Item1 [Button]
 Item2 [Button]


i want it to look like


Item1  [Button]
 Item2 [Button]
Item3  [Button]


Any way that i can do this..? Please help


Hello. I need vertical headers in my Datagrid.

I'm using this template:

<DataTemplate x:Key="RotateHeaderTemplate" > 

 <TextBlock Text="{Binding}" >


 <RotateTransform Angle="-90" />




Then i'm adding columns like this:

new DataGridTextColumn
Header = "header",
HeaderTemplate = (DataTemplate)Resourses["RotateHeaderTemplate"],
Binding = new Binding("mark")

And then i get smth like this: http://img265.imageshack.us/img265/7585/headers1.png

But i need headers aligned to bottom. Like here http://img695.imageshack.us/img695/2765/headers2.png

How can i do it?

how can i right align header text i have already right aligned column with extending my own class from DataGridTextBoxColumn & overriding paint but i still cant change header text alignment can you help

I need a few rows of text where the left column contains some labels, the right column contains some data, and the middle column contains a series of periods that connect the labels to the matching data. Something like this:


Label 1...............................value 1

Label Two..........................value two

Label Number Three......value number three



Hopefully it will show up okay, but the idea is that the data on the right is all aligned on the first character and the periods always fill up the empty space between each label and data value. The controls are bound to data that will change so you can't rely on widths.


I can achieve something that kind of works using dock panels and textblocks, but I don't know how to make the period character repeat so it always fills up the required space.

I have several locations on my site that have tables inside elements such as
divs that specify the text-align:center; CSS property. When IE8 is not in
compatibility mode, this is ignored by tables that are children of the tag
the property is specified in. I have only noticed this with table tags.
Here is a simple page I have written to demonstrate this:

<html xmlns="http://www.w3.org/1999/xhtml">



When you run this in IE8, be sure to try viewing it in compatibility and
non-compatibility mode. Correct me if I'm wrong, but I believe that when
following standards, text-align:center; should center any children. If IE6,
IE7, and IE8 Compatibility Mode follow this simple standard, why would
Microsoft not follow the standard in IE8's non-compatibility mode? Is this a
bug, is there some reason I don't know of, or is there really something
wrong with my code? Thanks.
Nathan Sokalski



For an SSRS matrix report, i need to vertical align the text in a label.
I have set the Writing Mode proporty of the label to 'Vertical'.
But when i have incorporated it to CRM 4.0 and run the report. Then the column width is not ending. Please help. 


i have problem using 'text-align' to align a login server control in <div> tags.


<div id="logIn">
    <asp:Login ID="LogIn" runat="server"...>...</login>

in css file:

    text-align:center ;

It works ok in IE, however, in any browser besides IE, the login control is aligned to left. Acctually, it works well with most controls but login control.

anyone can help? thx in advance.

I have a matrix with a table in it. All my settings are set to have the text on the top. But it seems to start writting from the botton, so on a row, the column with the most text in it is aligned to the top of that cell, other text in other columns on the same row are not at the top because they are shorter.



Hi all,

How to make the CheckBox text align vertically middle


Babu Kumarasamy.


I have an asp label and asp radiobuttonlist on the same line and need to get the text to align.  I understand the rbl renders as an html table.  The table appears to have spacing around the td elements, which pushes the text down.

Here's my code and CSS.  How can I get the text to align in a way that will work across browsers, text size and resolution settings?


	font-size: 1.2em;
	line-height: 1.4em;
	vertical-align: top;

	font-size: 1.2em;
	line-height: 1.4em;
    border: solid 1px black;

.RadioButtonList td
    border: solid 1px black;

    float: left;
    padding: 0em 0em 0 0.5em;

#tableadjusterContainer span
    float: left;
    border: solid 1px black;


        <div id="tableadjusterContainer">
            <asp:label ID="llbMissing" runat="server" Text="Show missing responses?" CssClass="Label"></asp:label>
                <asp:RadioButtonList ID="rblMissing" runat="server" RepeatDirection="Horizontal" AutoPostBack="true" CssClass="RadioButtonList">
                    <asp:ListItem Value="N" Text="No" Selected="True"></asp:ListItem>
                    <asp:ListItem Value="Y" Text="Yes"></asp:ListItem>







I have several textboxes that are 22 pixels wide. The properties window only gives me the option for left. The max length of the textboxes is 1 character. How can I center that 1 character in the textbox. The "I"'s look really bad.

so i wrote this style to my sharepoint site but when i add bullets the text ingnores padding when the bullets text starts a new line

heres my css

padding-left:50px !important;

so any help is appreciated

Why is that behaviour?

I am not able to find the vertical alignment. Can anyone shows me how is it done? Thank you

I have a richtextbox1 and few buttons for left center right justify top middle and bottom.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure