Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Questions/Problems with subclassing controls and forms
Message
From
07/08/2010 13:33:01
 
 
To
07/08/2010 11:52:09
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01475116
Message ID:
01475611
Views:
35
Hi Bonni!

It depends :))))

1) This code - allow to close modal form after click
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.DialogResult = Nothing
        Me.Close()
    End Sub
2) This code - not allowed you to close modal form after click :))
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
        Me.DialogResult = Nothing
    End Sub
But... when you use
Me.Close()
Me.DialogResult = Windows.Forms.DialogResult.OK
It close form as expected.

Try it, it does matter :))

It could be looks not logically to use Me.Close before set the DialogResult value.. but with Subclassing it does matter, because in first order works parent class code.. and then subclass code will be executed. When parent class code has Me.Close() and in the subclass code DialogResult set to Nothing - form will never closed by button click.
This was a reason why I wrote this comment.

Denis


>Hi Denis,
>
>>In the button code you should not use PARENT.. its mistake..
>
>Yes, I agree ... and I probably should have mentioned that also in my earlier reply to Thomas (which, like your post, was about using interfaces).
>
>>3) Why you showDialog could not closed - reason. Form.DialogResult is NOTHING!. Set the DialogResult to correct value before Me.Close.
>
>No, that's not the problem. Try it, it doesn't matter. Any Form can be shown modally ... and so it doesn't necessarily have to set a DialogResult.
>
>~~Bonnie
>
>
>
>
>>Hi Thomas,
>>.Net offer too many ways to do simple thing more complicated and complex thing easy :)
>>
>>At the first.. just some comments, I'd like to expose forms using interface when you try to call DoExit method.. this is more good style
>>So it must looks like
>>Public Interface IMyFormInterface
>> Sub DoExit()
>>End Interface
>>
>>Public Class MyForm
>> Inherits System.Windows.Forms.Form
>> Implements IMyFormInterface
>>
>>
>>When you develop framework - its more good way .
>>
>>Second.
>>
>>In the button code you should not use PARENT.. its mistake..
>>You should use a code like
>>
>>Dim loParentForm as System.Windows.Forms.Form = Me.FindForm()
>>IF Not IsNothing(loParentForm)
>> Dim loMyFrameworkForm as IMyFormInterface = TryCast(loParentForm, IMyFormInterface)
>> IF Not IsNothing(loMyFrameworkForm)
>> loMyFrameworkForm.DoExit()
>> END IF
>>END IF
>>
>>In this case you have interllisense and don't use reflection. I repeat - parent should not be used, because it could have reference not to the form. Offer to use to use FindForm() FindControl() and so on.. and then convert type.
>>
>>
>>3) Why you showDialog could not closed - reason. Form.DialogResult is NOTHING!. Set the DialogResult to correct value before Me.Close.
>>
>>
>>Denis.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform