Question

I have Form1, which is an MDI form. In Form2 (ChildForm) I have a rich text box.

I have a menu strip that contains a "Format" option. Under this I have font, size, and color. Changing the font and size through the Font method was easy, but color seems to be a different story.

I also am not able to directly call on the rich text box since it is in the child form, and a new child form isn't being created upon the color change.

//when Black is clicked in Color/Format
private void blackToolStripMenuItem_Click(object sender, EventArgs e)
{
    //change color to black

}

//when Red is clicked in Color/Format
private void redToolStripMenuItem_Click(object sender, EventArgs e)
{
    //change color to red

}


Bonus Question:

I am also having a problem with the child form re sizing when you change the size to something large. The entire child form gets bigger instead of the size of the text. If you go back to a smaller text size, the child form stays the same size and the richTextBox becomes smaller. This is the code for a text size change. Any ideas here?

//when 8 is clicked in Size/Format
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
    //change size to 8
    ActiveMdiChild.Font = new Font(ActiveMdiChild.Font.Name, 8);
}

Is there a property that I need to change to keep the box from re sizing?

Was it helpful?

Solution

If you want to work with the controls in the child form you can use the Controls collection and refer to the richTextBox using the name of the control. For example if I have a richTextBox named richTextBox1 I can use the following code to refer from the MDI parent:

ActiveMdiChild.Controls["richTextBox1"].ForeColor = Color.Blue; 

For your bonus question I was wondering if you tried the AutoSize property in the child and set it up to False.

Richard

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top