C# 添加一个';标签';控制到a';RichTextBox';
将C# 添加一个';标签';控制到a';RichTextBox';,c#,label,richtextbox,C#,Label,Richtextbox,将标签控件添加到RichTextBox时遇到问题。显然,代码中一定有我遗漏的东西。如果有人能指出我的疏忽,我将不胜感激。我知道两个控件都已创建,但标签不显示在RichTexBox的顶部……而是在其后面创建的 一般来说,您需要做的就是在标签上添加一个文本值!你应该注意每个控件的x-y坐标 RichTextBox richBox8 = null; Label label8 = null; private void button1_Click(object sender, EventArgs e) {
标签
控件添加到RichTextBox
时遇到问题。显然,代码中一定有我遗漏的东西。如果有人能指出我的疏忽,我将不胜感激。我知道两个控件都已创建,但标签
不显示在RichTexBox
的顶部……而是在其后面创建的
一般来说,您需要做的就是在标签上添加一个文本值!你应该注意每个控件的x-y坐标
RichTextBox richBox8 = null;
Label label8 = null;
private void button1_Click(object sender, EventArgs e)
{
richBox8 = new RichTextBox();
richBox8.Location = new System.Drawing.Point(1, 1);
richBox8.Size = new System.Drawing.Size(300, 200);
richBox8.Name = "richTextBox8";
Controls.Add(richBox8);
label8 = new Label();
label8.Location = new System.Drawing.Point(5, 5);
label8.Name = "label8";
label8.Size = new System.Drawing.Size(110, 25);
label8.Text = "hello world"; // crucial, if there is no text, you won't see any label!
richBox8.Controls.Add(label8);
// adding the label once again to the form.Controls collection is unnecessary
}
虽然可以将标签添加到RichTextBox
控件中,但我认为这不是很有用!RichTextBox
可用于显示和格式化文本:
不同的项目需要不同的任务。我正在试验RichTextBox和标签,因此我需要知道它们是如何协同工作的。谢谢你的回答,非常有帮助。
RichTextBox richBox8 = null;
Label label8 = null;
private void button1_Click(object sender, EventArgs e)
{
richBox8 = new RichTextBox();
richBox8.Location = new System.Drawing.Point(1, 1);
richBox8.Size = new System.Drawing.Size(300, 200);
richBox8.Name = "richTextBox8";
Controls.Add(richBox8);
label8 = new Label();
label8.Location = new System.Drawing.Point(5, 5);
label8.Name = "label8";
label8.Size = new System.Drawing.Size(110, 25);
label8.Text = "hello world"; // crucial, if there is no text, you won't see any label!
richBox8.Controls.Add(label8);
// adding the label once again to the form.Controls collection is unnecessary
}
public Form1()
{
InitializeComponent();
richTextBox1.Text = "demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text demo text ";
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Select(10, 20);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.Select(25, 30);
richTextBox1.SelectionFont = new Font("Verdana", 12);
}