I’m having trouble adding a Label control to a RichTextBox. Clearly, there must be something that I’m missing in the code. I would appreciate it if someone could point out my omission. I know both of the controls are created, but the Label is not displayed on top of the RichTexBox…instead, it’s created behind it.
RichTextBox richBox8;
Label label8;
private void create()
{
richBox8 = new RichTextBox();
richBox8.Location = new System.Drawing.Point(957, 95);
richBox8.Size = new System.Drawing.Size(159, 50);
richBox8.Name = "richTextBox8";
Controls.Add(richBox8);
label8 = new Label();
label8.Location = new System.Drawing.Point(984, 106);
label8.Name = "label8";
label8.Size = new System.Drawing.Size(110, 25);
label8.Text = ""
Controls.Add(label8);
richBox8.Controls.Add(label8);
}
In general all you have to do is add a text value to your label! And you should pay attention to the x-y coordinates for each of your controls.
And although it is possible to add a label to a
RichTextBoxcontrol, I don’t think it is very useful! ARichTextBoxcan be used to display and format text: