PetCar
Member
How do i reuse a class from withing two diffrent forms?
clsCommon is to be used with both frmMain and frmSettings, but when starting the second form (frmSettings) i get "Specified cast is not valid".
The code i use is:
When clicking button4 to show the frmSettings i get the error "Specified cast is not valid".
I know that there is some error in clsCommon:
But how can i do this different?
Im so into the old VB6 that my mind is twisted..
Thanks!
// Peter
clsCommon is to be used with both frmMain and frmSettings, but when starting the second form (frmSettings) i get "Specified cast is not valid".
The code i use is:
Code:
#clsCommon
Public Class clsCommon
Private objForm As frmMain
Public Sub New(ByVal objCallingForm As Form)
objForm = objCallingForm
End Sub
Public Sub DoSomething()
objForm.change_form_in_some_way
End Sub
End Class
#frmMain
Public Class frmMain
Inherits System.Windows.Forms.Form
Private clsCommon As New clsCommon(Me)
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim frmSettings As New frmSettings
frmSettings.Show()
End Sub
End Class
#frmSettings
Public Class frmSettings
Inherits System.Windows.Forms.Form
Private clsCommon As New clsCommon(Me)
Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
clsCommon.ShowUserMessage(0, , "Hej hej", True, False)
End Sub
End Class
When clicking button4 to show the frmSettings i get the error "Specified cast is not valid".
I know that there is some error in clsCommon:
Code:
Private objForm As frmMain
Im so into the old VB6 that my mind is twisted..
Thanks!
// Peter