Still learning c#. I am creating an ObjectListView, and this among other things is capturing button clicks.
public partial class MainForm : Form
{
private FormSpecParser parser;
private static ObjectListviewForm form;
public MainForm()
{
InitializeComponent();
createMainForm();
}
private void createMainForm()
{
form = new ObjectListviewForm();
form.Populate(parser.ParsedSpec);
form.Show(this);
}
}
public partial class ObjectListviewForm : Form
{
...
void b_Click(object sender, EventArgs e)
{
Button b = sender as Button;
if (b == null) return;
var button = GetFormSpecButton(b.Name);
MessageBox.Show(button.ClickMessageBoxStub);
}
}
I have 2 problems: 1) how do I get the ObjectListView to tell MainForm that a button was clicked, please deal with it.
2) I want the ObjectListView Form to be the first one the user sees, and when the ObjectListView form closes, the program closes. Right now the ObjectListView Form does appear, but "behind" it is a blank form, and when ObjectListView Form is closed, control seems to pass back to this blank form instead of exiting.
1) You passed MainForm as Owner to Show method - form.Show(this). This means that in ObjectListviewForm you can call method from MainForm like this:
(this.Owner as MainForm).MethodInMainform();
2) In Program.cs file You should have line like this:
Application.Run(new MainForm());
change it to:
Application.Run(new ObjectListviewForm ());