Cross form communication...

H

hzgt9b

Using VS2005, VB.NET, I have am developing a windows app that has a
login form. This login form can be called by several classes. When the
login form is able to verify that the supplied credentials are valid
then I want to pass an object (System.Net.Credential) back to the
calling/parent class. All the classes that call the login form have a
public property named "_oCredentials" that could be used to store
validated credentials.

My problem is knowing what class opened/called the login form and
getting the code in the form to store the validated credentials back
in the correct parent...

Hope this makes sense. Your input appreciated.

FYI, here is how I am calling the form now (from any of the "parent"
classes)
'Gather domain credentials
Dim frmLogin As New frmDomainLogin
frmLogin.ShowDialog(Me)
 
C

Charlie Brown

Using VS2005, VB.NET, I have am developing a windows app that has a
login form. This login form can be called by several classes. When the
login form is able to verify that the supplied credentials are valid
then I want to pass an object (System.Net.Credential) back to the
calling/parent class. All the classes that call the login form have a
public property named "_oCredentials" that could be used to store
validated credentials.

My problem is knowing what class opened/called the login form and
getting the code in the form to store the validated credentials back
in the correct parent...

Hope this makes sense. Your input appreciated.

FYI, here is how I am calling the form now (from any of the "parent"
classes)
'Gather domain credentials
Dim frmLogin As New frmDomainLogin
frmLogin.ShowDialog(Me)

You could create a interface for all your parent forms to implement.
Call it something like iCallTheLoginForm or whatever is appropriate.
Then in your login form you can reference the parent form by casting
it to your interface.

Public Interface iCallTheLoginForm
Public Property LoginCredential as System.Net.Credential
End Interface

Public Class MainForm
implements iCallTheLoginForm

Public Property MainForm_LoginCredential As System.Net.Credential
Implements iCallTheLoginForm.LoginCredential

.....

Public Class LoginForm

Private myParent as iCallTheLoginForm

Public Sub New(p as iCallTheLoginForm)
myParent = p
End Sub

.....


That should be a good start, I quick typed that one, so it might have
a typo...
 
H

hzgt9b

You could create a interface for all your parent forms to implement.
Call it something like iCallTheLoginForm or whatever is appropriate.
Then in your login form you can reference the parent form by casting
it to your interface.

Public Interface iCallTheLoginForm
Public Property LoginCredential as System.Net.Credential
End Interface

Thanks for the quick response... unfortunately I am unable to declare
a property of type "System.Net.Credential" as the return type in the
interface (even after importing System.Net)...
 
G

Guest

what i usually do in this situation, is overload the ShowDialog function wiht
my own return type, then do the base form's showdialog then return the
info....ex

Public Overloads Function ShowDialog() As String

MyBase.ShowDialog()

Return String.Empty

End Function

and there ya go. hope this helps
 
H

hzgt9b

Thanks, I implemented an interface and then did the case back to the
form... works great.
 

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