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
Title:
Questions/Problems with subclassing controls and forms
Miscellaneous
Thread ID:
01475116
Message ID:
01475116
Views:
117
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
Next
Reply
Map
View

Click here to load this message in the networking platform