How to make the process.Arguments run for each label its own?

 con.Open(); var reader = cmd.ExecuteReader(); var i = 0; while (reader.Read()) { var cm = new ContextMenu(); cm.MenuItems.Add("Подробнее", ToolStrip); cm.MenuItems.Add("Подключиться", StartProc); var _label = new Label(); _label.Text = reader["Name_PC"].ToString(); _label.Location = new Point(20, 25*(i++)); _label.BorderStyle = BorderStyle.Fixed3D; _label.Click += delegate { _label.ContextMenu = cm; }; Controls.Add(_label); process.Arguments = _label.Text; 

So it works only on the last argument received, i.e. 1 argument got the previous one forgot. How to fix?

  • Create while each time a new process. - Monk
  • one
    Try to give an example completely. It is desirable that it would be visible where and what variables are declared. For example, where is your process variable declared? - Stepan Kasyanenko
  • I hope this example is purely educational, and you understand why reading from a database in a UI stream means application hanging. - VladD

1 answer 1

found a solution. Just needed to move

 process.Arguments = _label.Text; 

at

  _label.Click += delegate { _label.ContextMenu = cm; process.Arguments = _label.Text; }; 

and it all worked as it should