There is a rich textbox, the text in it is changed by clicking the button, each piece of text has its own title.

I figured out how to select a heading and change its color, is it possible to make it bold, center it, and make it bigger than the text under it?

On loading form:

richTextBox1.BackColor = Color.White; int newFontSize = 16; //Ρ€Π°Π·ΠΌΠ΅Ρ€ richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, (float)newFontSize); 

By clicking:

 richTextBox1.Text = "ΠŸΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹: тСхнология, Π²ΠΈΠ΄Ρ‹, производство ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅.\nΠŸΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹ - это химичСскиС высокомолСкулярныС соСдинСния, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ состоят ΠΈΠ· многочислСнных маломолСкулярных ΠΌΠΎΠ½ΠΎΠΌΠ΅Ρ€ΠΎΠ² (звСньСв) ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΠΎΠ³ΠΎ строСния. Π—Π°Ρ‡Π°ΡΡ‚ΡƒΡŽ для изготовлСния ΠΏΠΎΠ»ΠΈΠΌΠ΅Ρ€ΠΎΠ² ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΌΠΎΠ½ΠΎΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Ρ‹: этилСн, Π²ΠΈΠ½ΠΈΠ»Ρ…Π»ΠΎΡ€ΠΈΠ΄, Π²ΠΈΠ½ΠΈΠ»Π΄Π΅Π½Ρ…Π»ΠΎΡ€ΠΈΠ΄, Π²ΠΈΠ½ΠΈΠ»Π°Ρ†Π΅Ρ‚Π°Ρ‚, ΠΏΡ€ΠΎΠΏΠΈΠ»Π΅Π½, ΠΌΠ΅Ρ‚ΠΈΠ»ΠΌΠ΅Ρ‚Π°ΠΊΡ€ΠΈΠ»Π°Ρ‚, тСтрафторэтилСн, стирол, ΠΌΠΎΡ‡Π΅Π²ΠΈΠ½Ρƒ, ΠΌΠ΅Π»Π°ΠΌΠΈΠ½, Ρ„ΠΎΡ€ΠΌΠ°Π»ΡŒΠ΄Π΅Π³ΠΈΠ΄, Ρ„Π΅Π½ΠΎΠ». Π”Π°Π»Π΅Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎ рассмотрСно, Ρ‡Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ ΠΏΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹, ΠΊΠ°ΠΊΠΎΠ²Ρ‹ ΠΈΡ… химичСскиС ΠΈ физичСскиС свойства, классификация ΠΈ Π²ΠΈΠ΄Ρ‹. "; richTextBox1.Select(0, "ΠŸΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹: тСхнология, Π²ΠΈΠ΄Ρ‹, производство ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅.".Length); richTextBox1.SelectionColor = Color.DarkGray; 

UPD1: Found center alignment, but did not apply to the title as a piece of text. richTextBox1.SelectionAlignment = HorizontalAlignment.Center;

  • I think you need to refuse to work with RTF through RichTextBox. You have already realized that this is extremely inconvenient. And besides, it works very slowly. Use any library to work with RTF. In particular, here or here . - Alexander Petrov

1 answer 1

 using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Π¨Ρ€ΠΈΡ„Ρ‚(Font) Π‘Π°ΠΌ ΡˆΡ€ΠΈΡ„Ρ‚,Ρ€Π°Π·ΠΌΠ΅Ρ€,ΡΡ‚ΠΈΠ»ΡŒ richTextBox1.Font = new Font("Consolas", 18f, FontStyle.Bold); //МСняСм Ρ†Π²Π΅Ρ‚ Ρ„ΠΎΠ½Π° richTextBox1.BackColor = Color.AliceBlue; string[] words = { ... }; Color[] colors = { ... }; //some code } } } 

UPD: I think that you can not change a separate text

  richTextBox1.Font = new Font("Consolas", 10f, FontStyle.Strikeout); richTextBox1.Text += "Hello \n"; richTextBox1.Font = new Font("Consolas", 26f, FontStyle.Italic); richTextBox1.Text += "World"; 

I tried in many ways.

  • Little did not understand. You need to resize the header and center it in richtextbox . This decision will affect all the text inside the container, or I misunderstand a little how to use - LokenGarvel '28
  • You can, here's an example) richTextBox1.Select(0, "ΠŸΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹:\n тСхнология, Π²ΠΈΠ΄Ρ‹, производство ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅.".Length); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.SelectionColor = Color.Black; richTextBox1.Select(0, "ΠŸΠΎΠ»ΠΈΠΌΠ΅Ρ€Π½Ρ‹Π΅ ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»Ρ‹:\n тСхнология, Π²ΠΈΠ΄Ρ‹, производство ΠΈ ΠΏΡ€ΠΈΠΌΠ΅Π½Π΅Π½ΠΈΠ΅.".Length); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.SelectionColor = Color.Black; - LokenGarvel '28
  • The only thing that does not come out is to change the size of the header. - LokenGarvel '
  • @LokenGarvel 'I mean the font, how did you make a different font on the lines? PS Pts are interesting to me - TEA
  • c using the selected text, we take something in the block, and work further only with it. For example: richTextBox1.Select (0, "Calender method \ n of the production of polymer films.". Length); `, and now all further actions will take place with selective text - richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.SelectionColor = Color.Black; and so on - LokenGarvel '