This problem has little to do with the UI in general and
System.Windows.Forms
in particular, but you haven't done anything reasonable to show the results, not even remotely. How could you expect that some control like a label would act as a console? You simply assign the value to some property (
Text
, int this case) in the cycle, but why? In each iteration,
old value of the property gets discarded, and you replace it with another value. It's hard to imagine how could you even come to such a weird idea.
But isn't the problem simple. Just to think about it: if you are already using some list, wouldn't it be natural to use some list-related control to present things? You could use
System.Windows.Forms.ListBox
, as a simplest thing:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox%28v=vs.110%29.aspx.
Alternatively, by some reasons related exclusively to some graphic rendering subtleties, I often use
TreeView
instead, with just one level of hierarchy, without any child nodes.
In this way, you can just add (
Items.Add
) new items:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.items%28v=vs.110%29.aspx,
https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.objectcollection%28v=vs.110%29.aspx.
Also, you may want to
bind some list to a list box or other control:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.bindingcontext(v=vs.110).aspx,
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.databindings(v=vs.110).aspx,
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.resetbindings(v=vs.110).aspx,
https://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.onbindingcontextchanged(v=vs.110).aspx.
—SA