O
O
oatcookie2017-01-15 17:07:57
Command line
oatcookie, 2017-01-15 17:07:57

How to create an object in WinForms and hang a handler?

How to create an object in a loop using WinForms?
The program receives a string from the site and splits it by the delimiter, so an "array" of contacts is formed.
You need to create a "Label" object and attach a click handler to it.
Are there good examples?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Evseev, 2017-01-19
@oatcookie

int y = startY;
this.SuspendLayout();
foreach(var contact in GetContactsFromSite())
{
     Label lbl = new Label();
     lbl.Text = contact.Name;
     lbl.Location = new Point(startX,y);
     y += lbl.Height + 4;
     lbl.Click += (s,e) => {  /*some handler */ };
     this.Controls.Add(lbl);
}
this.ResumeLayout();

I think something like that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question