AllTheTimeWorld.com

csharp richtextResize: Rich text box fills the form.

Resize: Rich text box fills the form.

Richtext box fills the lower part of the form: between the toolstrip and the statusbar

Resize: Rich text box fills the form.

Richtext box fills the lower part of the form: between the toolstrip and the statusbar

We have created an Application called Notes with a rich text box, a menu with standard items, a toolstrip, and a status bar.

We are going to write code so that the richtext box fills the lower part of the form: between the toolstrip and the statusbar.
We want to do this at form load and also whenever the form is resized. We will create a function and call it from both form load and form resize:

Write the code as shown below:

private void Form1_Load(object sender, EventArgs e)
{
  // Position the rich text box to left, under the toolstrip.
  richTextBox1.Top = toolStrip1.Top + toolStrip1.Height;
  richTextBox1.Left = 0;
  resizeRichText();
}

private void Form1_Resize(object sender, EventArgs e)
{
   // In design mode,Select the form, in properties, click events, add resize:
   resizeRichText();
}

private void resizeRichText()
{
   // Rich text box will fill the form between the toolstrip and the status bar.
   richTextBox1.Width = this.Width;
   richTextBox1.Height = statusStrip1.Top - richTextBox1.Top;
}
  • Click Save All at this point and run the program to see what you have so far.