Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Questions/Problems with subclassing controls and forms
Message
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01475116
Message ID:
01475513
Views:
34
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.






>Hi there,
>
>moving an app from VFP to VB.Net I started building some classes but I am getting to the point where
>I am encountering some problems and need some advice. What I do is this:
>
>1) Build a Button class which serves as my base class:
>
>...
>Public Class cmdbase
>    Inherits System.Windows.Forms.Button
>...
>
>
>This class sets just some properties which all buttons have in common like size, color etc.
>
>2) I Build buttons for special purposes from that class:
>
>
>Public Class cmdexit
>    Inherits cmdbase
>
>
>This button gets a special text, an image and some special behaviour:
>
>
>    Public Sub New()
>        MyBase.New()
>        InitializeComponent()
>        'Me.Text = "&Ende"
>        Me.ImageAlign = System.Drawing.ContentAlignment.TopCenter
>    End Sub
>    Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
>        MyBase.OnPaint(pevent)
>        Me.Text = "&Ende"
>    End Sub
>  Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
>        Dim meth As MethodInfo = Me.Parent.GetType().GetMethod("DoExit")
>        If meth = Nothing Then
>            'MsgBox("Methode fehlt")
>        Else
>            'MsgBox("Methode da")
>            meth.Invoke(Me.Parent, Nothing)
>        End If
>        MyBase.OnClick(e)
>    End Sub
>
>
>There is a baseform which has a DoExit-Method which just executes the me.close() command.
>
>
>    Public Overridable Sub DoExit()
>        If Not Me.lIsRunning Then    ' A property to check if the form is busy
>            MsgBox("Base doexit")
>            Me.Close()
>        Else
>            MsgBox("Isrunning")
>        End If
>    End Sub
>
>
>This button shall look if his parent (a Form) has a Method doexit and if, shall execute it.
>When I put this button on a form inherited from my baseform (My startform) , everything works fine.
>But when I load another form from my startform with
>
>
> dim frm as new form2
>frm.showdialog()
>
>
> the method in the baseform is executed (I have same messageboxes implemented for testing reasons) but the
>me.close-command does not have any impact, the form does not close. If I put another button for testing purposes
>on the form which issues a close()-command, it works, if I change the calling of form2 to non-modal, it works too.
>Could anybody tell me, what I am doing wrong.
>
>Thanks in advance
>
>Thomas
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform