0

HI again!!!!!!!!!
so i have this button where if i press it words will be typed on my richtextbox but my problem is i want the half part to be centered and the half part would be aligned to the left. how can i achieved that. i have already done tha centered part wahat i did was...

  private void buttonX1_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
            richTextBox1.Text = //enter texts;
            }

how can i do the left aligned text following that. THANK YOU AND MORE POWER!!!!!!!

4
Contributors
4
Replies
22
Views
2 Years
Discussion Span
Last Post by kidkardel
Featured Replies
  • Do you mean that you want the first half to be centered on top and then the second part below it to be left alinged? this is a very simple example you can test for yourself. If indeed i'm understanding you correctly richTextBox1.AppendText("Header"); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText(System.Environment.NewLine); richTextBox1.AppendText("First Line"); richTextBox1.SelectionAlignment … Read More

  • 1

    Use the SelectionStart and SelectionLength properties to select a particular part of the text and then apply formatting to it. Example: richtextbox1.SelectionStart = 30; richtextbox1.SelectionLength = 10; richtextbox1.SelectionAlignment = HorizontalAlignment.Left; will align the substring starting at index 30 of length 10 to the left. I'm not sure how multiple alignments … Read More

  • 1

    You can do it by altering SelectionStart and SelectedText Property of the RTBox. private void buttonX1_Click(object sender, EventArgs e) { richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.Text = "//enter texts"; richTextBox1.Text +=System.Environment.NewLine ; richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.SelectionAlignment = HorizontalAlignment.Left; richTextBox1.SelectedText += "//enter text"; } Read More

1

Do you mean that you want the first half to be centered on top and then the second part below it to be left alinged?

this is a very simple example you can test for yourself. If indeed i'm understanding you correctly

richTextBox1.AppendText("Header");
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
richTextBox1.AppendText(System.Environment.NewLine);
richTextBox1.AppendText("First Line");
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;

Edited by Fenrir()

1

Use the SelectionStart and SelectionLength properties to select a particular part of the text and then apply formatting to it.

Example:

richtextbox1.SelectionStart = 30;
richtextbox1.SelectionLength = 10;
richtextbox1.SelectionAlignment = HorizontalAlignment.Left;

will align the substring starting at index 30 of length 10 to the left. I'm not sure how multiple alignments on the same line will work though but I'll leave that for you to test.

1

You can do it by altering SelectionStart and SelectedText Property of the RTBox.

private void buttonX1_Click(object sender, EventArgs e)
        {
             richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
            richTextBox1.Text = "//enter texts";

            richTextBox1.Text +=System.Environment.NewLine ;

            richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
            richTextBox1.SelectedText += "//enter text";

            }

Edited by Shark_1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.