Hi,
Typically, we try to separate concerns, we use the Form constructor(s) to pass data from the main class to the Form class and public properties in the Form class which can be accessed by the instance of the Form created in the main class.
Here's a simple example:
in the Form class
public partial class MshTry : Form
{
// get the selected item in the list box
public string Layer => (string)listOfObjects.SelectedItem;
public ModalDialog(List<string> objects)
{
InitializeComponent();
// Set the DialogResult property of the OK and Cancel buttons
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = Dialogresult.Cancel;
// fill the list box with the input list
listOfObjects.DataSource = objects;
}
}
in the main class
var objects = new List<string>() { "One", "Two", "Three" };
// create a new instance of MshTry passing it the lis of objects
using (var dialog = new MshTry(objects))
{
// show the dialog box
var dlgResult = Application.ShowModalDialog(dialog);
// check for the way the dialog was closed by the user (typically OK or Cancel)
if (dlgResult == System.Windows.Forms.DialogResult.OK)
{
// get the selected item in the dialog
selectedObject = dialog.Layer;
// do your stuff...
}
}
Note you should use Application.ShowModalDialog or Application.ShowModelessDialog methods to show your form from AutoCAD, see these topics:
https://www.keanw.com/2008/08/the-right-way-t.html
https://adndevblog.typepad.com/autocad/2012/06/displaying-modal-and-modeless-forms-in-autocad-net.ht...