如何在面板上用c#写文本?
我想点击一个按钮,然后在面板上写下一个特定的文本 我尝试过“panel.items.add(Text1);”但没有成功如何在面板上用c#写文本?,c#,panel,windows-forms-designer,C#,Panel,Windows Forms Designer,我想点击一个按钮,然后在面板上写下一个特定的文本 我尝试过“panel.items.add(Text1);”但没有成功 private void Button1_Click(object sender, EventArgs e) { TextSchreiben("Text"); } private void Panel1_Paint(object sender, PaintEventArgs e) { } public
private void Button1_Click(object sender, EventArgs e)
{
TextSchreiben("Text");
}
private void Panel1_Paint(object sender, PaintEventArgs e)
{
}
public string TextSchreiben(string Text1)
{
panel1.items.add(Text1);
return Text1;
}
用法将是
bool created = textSchreiben("your text", 0 *x cords, 0 *y cords);
或使函数无效。向面板添加标签控件。将文本值设置为空字符串。然后单击按钮时,用消息填充标签的文本值
您还可以使用消息预填充标签并切换可见性。您需要使用自定义绘制(我一般不推荐使用),或者使用给定文本添加控件(例如标签)。@Jon Skeet您的意思是我只是在面板上放置标签,并对标签而不是面板进行寻址?所以我必须键入“label1.items.add(Text1);”?不,您需要执行类似于
panel1.items.add(新标签{Text=Text1})的操作代码>。请注意,C#区分大小写,因此项。添加而不是项。添加感谢您的帮助:)
bool created = textSchreiben("your text", 0 *x cords, 0 *y cords);