通过单击按钮创建带有文本的标签 vb.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21569515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a label with text by clicking a button vb.net
提问by TheNewbie
I would just like to ask a question how do I create or generate a label once I clicked a button. For example I typed something on a textbox on form1 for example "hello" then it will create a label on form2 with the text that i type.
我想问一个问题,一旦我点击了一个按钮,我该如何创建或生成一个标签。例如,我在 form1 的文本框中键入了一些内容,例如“hello”,然后它将在 form2 上使用我键入的文本创建一个标签。
回答by pankeel
try this code for create label
试试这个代码来创建标签
this a global variable in module
这是模块中的全局变量
public lbl as new label
this code write into button click;
此代码写入按钮单击;
lbl.text=textbox1.text
this code add into thr frm2 the load event..
此代码将加载事件添加到 thr frm2 中。
me.controls.add(lbl)
回答by Mark Hall
Not sure exactly what you are trying to do, if you are wanting to create a label and add it to your 2nd form or add your text to an existing label on your second form. This sample code will do the first option
如果您想创建一个标签并将其添加到您的第二个表单或将您的文本添加到您的第二个表单上的现有标签,则不确定您到底要做什么。此示例代码将执行第一个选项
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm2 As Form2 = New Form2 'Create your Form
Dim lbl As Label = New Label 'Create your Label
lbl.Location = New Point(50, 50) 'Set Label Location
lbl.Text = TextBox1.Text 'Set Label Text
lbl.ForeColor = Color.Red 'Set Label ForeColor
frm2.Controls.Add(lbl) 'Add Label to it
frm2.Show(Me) 'Show Second Form
End Sub

