Testing for Modal form

M

Mark Broadbent

I am instantiating a form and calling it via the ShowDialog method. I am
testing for the forms modal property within it's Load event but the modal
property is always false.
Supposedly you can test for the modal property within Load event and above
(but it doesn't work in constructor by design). I get the same modal result
when showing a form via its Show method too.

Expected behaviour is
ShowDialog modal=true
Show modal=false

So why is this going wrong?

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
 
M

Mark Broadbent

well the problem lies with the code (theres a suprise :). The form is
instanciated by another form's button click event. The delegate that I added
to this new form uses "this" which seems to be referring back to parent
form.
Which raises a new problem (please first see code)
private void button1_Click(object sender, System.EventArgs e){

Form myForm = new Form();

myForm.Load += new System.EventHandler(Form_Load);


myForm.ShowDialog();

}


private void myForm_Load(object sender, System.EventArgs e){

if (this.Modal) MessageBox.Show("Modal");

else MessageBox.Show("Modeless");

}

I was under the impression that "this" referred to the current instance, but
when running the above code you will see that the delegate myForm_Load that
is added to the new forms Load event refers to the object instance of the
class that the delegate code myForm_Load belongs. If this is true then how
could I programmatically add a delegate method to the new form's load event
that refers to the this new form (without actually creating a separate
class module for the new forms definition)?

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
 
M

Mark Broadbent

p.s. "private void myForm_Load" should have read "private void Form_Load"

--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top