Winforms: system.windows.forms.label text displayed as text in label

守給你的承諾、 提交于 2020-01-07 14:19:59

问题


I have created a simple program. One of the functions is that it counts clicks, and when the program finishes, a label is displayed with some text and the number of clicks. The code works, but the problem is that the label displays extra text, like this: system.windows.forms.label text

Stevec is set to count clicks. Lable konec already contains text, and in this case I just want to add the extra sentence with the number of clicks.

konec.Text = konec + " Kliknil si: " + Stevec.ToString() + "-krat!";

If anyone has any idea how to display only the text that I have set in the code, I would appreciate it!


回答1:


You need the Text property instead of the control itself:

konec.Text = konec.Text + " Kliknil si: " + Stevec.ToString() + "-krat!";



回答2:


The reason that you have unwanted text is because of this part:

...konec +...

+ operator used with string implicitly converts other operand to string calling its ToString() method. This way, above part is equivalent to ...konec.ToString() + ... (which results in unwanted text), but what you want is ...konec.Text + ..., that is why your code should use konec.Text instead of just konec object.



来源:https://stackoverflow.com/questions/49716416/winforms-system-windows-forms-label-text-displayed-as-text-in-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!