I have two forms.
The LoadWorkstationFile prompts the users for the id that they want to load.
The DisplayDataForm displays the id's data that they selected on the previous screen.
In the DisplayDataForm they can click on an option to load new data, which calls the LoadDataForm as a ShowDiaglog:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
var answer = MessageBox.Show("Do you wish to save the current work file before continuing?", "Confirmation",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (answer == DialogResult.Cancel)
return;
if (answer == DialogResult.Yes)
SaveWorkFile();
var prevworkstationid = Configuration.WorkstationId;
var lw = new LoadWorkstationFile();
lw.ShowDialog(this);
if (Configuration.WorkstationId != prevworkstationid)
{
LoadData();
}
}
As you can see, I am prompting them again with the same screen as before.
In the LoadWorkstationFile it has the following code:
if (this.Parent == null)
{
var sc = new ScanCheck();
sc.Show();
this.Hide();
}
Initial load everything is fine. When I want to load data again it it has loaded, I end up with 2 of the LoadWorkstationFile screens cause Parent always equals null.
Do I have the wrong idea? Should the parent be the DisplayDataForm when it is called with .ShowDialog ?
Thanks as usual.
You should check the Owner
instead of the Parent
What you're setting in the constructor of ShowDialog is the Owner property. Which tells the form which other form "owns" it. The parent is (as indicated by Mario) described the ownership relationship for a Control.
so you should change your code to:
if (this.Owner == null)
{
var sc = new ScanCheck();
sc.Show();
this.Hide();
}
and it should work.
Parent is a property inherited from control which is used to describe embedding relationships ( a label has as parent the form).
I do not think it is set when using ShowDialog().
I assume that Owner is the correct property to check.
hth
Mario
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With