vb.net Visual Basic 如何向已有文本的标签添加文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37643180/
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
Visual basic how to add text to a label that already have text?
提问by Darkghost620
i wanted to know if there is a way to add or remove text to a label that already have text e.g i have a label that says "Hi," and when i press a button it add "My name is rick" next to "Hi," so that if i have a list of checkbox. Every time i check a box it add the name of that check box next to the previous one e.g. I have 5 check box named - door, screen, laptop, dog and cat - if i press cat the text is going to be "Cat," and then if i press laptop its going to add "Laptop," next to "Cat," so the text would be "Cat, Laptop" but if i uncheck cat it would only be "Laptop," i hope you understand what i mean and thanks to anyone that take the time to help me out.
我想知道是否有办法向已经有文本的标签添加或删除文本,例如我有一个标签,上面写着“嗨”,当我按下一个按钮时,它会在“嗨”旁边添加“我的名字是瑞克” ,”这样如果我有一个复选框列表。每次我选中一个框时,它都会在前一个旁边添加该复选框的名称,例如,我有 5 个名为的复选框 - 门、屏幕、笔记本电脑、狗和猫 - 如果我按猫,文本将是“猫, “然后如果我按下笔记本电脑,它会在“猫”旁边添加“笔记本电脑”,所以文本将是“猫,笔记本电脑”但如果我取消选中猫,它只会是“笔记本电脑”,我希望你明白我的意思意思是感谢任何花时间帮助我的人。
采纳答案by Darkghost620
To do this all you got to do is make a dim as string and add text on this string using +=(or &=) here is an e.g
要做到这一点,你所要做的就是将一个暗淡的字符串作为字符串并使用 +=( 或 &=) 在这个字符串上添加文本,这里是一个例子
Dim textTest As String
if checkbox1.checked = true then
textTest +=(or &=) ("Cat, ")
end if
if checkbox2.checked = true then
textTest +=(or &=) ("Laptop, ")
end if
hope this helped you.
希望这对你有帮助。

