473,408 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Inter-related form

Hello:

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to execute
a public method on FormA.
I am able to do it. But I want to generalize the design so that FormB can be
used with any form that required the functionality provided by FormB. Of
course, all these forms will have the public method that will be executed by
FormB.

Currently, I have it coded this way:

Private MyParentForm as FormA
Public Sub New(psForm as FormA)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

Thanks.

Venkat
Nov 21 '05 #1
7 1000
Hi Venkat,

Your method (create a formA with a method on it to use everywhere), is
against everything about OOP.

Create a class, which you use in FormB, FormC however as well in FormA.

Then you don't have to create something generic, it is the standard way to
go.

I hope this helps?

Cor

"vvenk" <vv***@discussions.microsoft.com>
Hello:

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to
execute
a public method on FormA.
I am able to do it. But I want to generalize the design so that FormB can
be
used with any form that required the functionality provided by FormB. Of
course, all these forms will have the public method that will be executed
by
FormB.

Currently, I have it coded this way:

Private MyParentForm as FormA
Public Sub New(psForm as FormA)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

Thanks.

Venkat

Nov 21 '05 #2
VenKat,

To remember me where you where talking about in your previous question where
I asked you not to multipost in this newsgroup almost the same messages.

Passing Currencymanager and DataTable to a class

Cor

"vvenk" <vv***@discussions.microsoft.com>
Hello:

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to
execute
a public method on FormA.
I am able to do it. But I want to generalize the design so that FormB can
be
used with any form that required the functionality provided by FormB. Of
course, all these forms will have the public method that will be executed
by
FormB.

Currently, I have it coded this way:

Private MyParentForm as FormA
Public Sub New(psForm as FormA)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

Thanks.

Venkat

Nov 21 '05 #3

"vvenk" <vv***@discussions.microsoft.com> wrote

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to execute
a public method on FormA. <...> Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

There are two general purpose ways to handle that, using events, or using interfaces.

Using events means that any form that wants to, can declare FormB WithEvents
such that FormB will raise the event for the parent form to act on. The parent
would not be required to listen for events, even while formB raises them as scheduled.

If the decision to act on FormB's event is supposed to be in the parent form, that
would be the way to go. If FormB requires that there be a routine to call in the
parent form, then use an interface.

Using interfaces means you declare an interface with the required method, and force
all callers to implement that interface to show FormB:
Private MyParentForm as IParentInterface
Public Sub New(psForm as IParentInterface)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub
That would assume you've declared an interface somewhere
(in a module perhaps):

Public Interface IParentInterface
Sub ExecuteFunction()
End Interface

And any form that uses FormB must implement that interface:

Public Class FormA
Inherits System.Windows.Forms.Form
Implements IParentInterface

'... <rest of form code>

Public Sub ExecuteFunction() Implements IParentInterface.ExecuteFunction
' FormB callback function goes here
End Sub

End Class
The calling syntax would be similar to what you are probably already
using:

Dim dialog As FormB = New FormB(Me)
dialog.Show()
HTH
LFS

Nov 21 '05 #4
Larry:

Awesome! Thank you!

Venkat

"Larry Serflaten" wrote:

"vvenk" <vv***@discussions.microsoft.com> wrote

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to execute
a public method on FormA.

<...>
Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

There are two general purpose ways to handle that, using events, or using interfaces.

Using events means that any form that wants to, can declare FormB WithEvents
such that FormB will raise the event for the parent form to act on. The parent
would not be required to listen for events, even while formB raises them as scheduled.

If the decision to act on FormB's event is supposed to be in the parent form, that
would be the way to go. If FormB requires that there be a routine to call in the
parent form, then use an interface.

Using interfaces means you declare an interface with the required method, and force
all callers to implement that interface to show FormB:
Private MyParentForm as IParentInterface
Public Sub New(psForm as IParentInterface)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub
That would assume you've declared an interface somewhere
(in a module perhaps):

Public Interface IParentInterface
Sub ExecuteFunction()
End Interface

And any form that uses FormB must implement that interface:

Public Class FormA
Inherits System.Windows.Forms.Form
Implements IParentInterface

'... <rest of form code>

Public Sub ExecuteFunction() Implements IParentInterface.ExecuteFunction
' FormB callback function goes here
End Sub

End Class
The calling syntax would be similar to what you are probably already
using:

Dim dialog As FormB = New FormB(Me)
dialog.Show()
HTH
LFS

Nov 21 '05 #5
Larry:

It almost worked but I get an error at compilation:

On FormB's Public New method:

Public Sub New(ByVal psForm As IParentFormDataGridSearchInterface)

it says "'psForm' cannot expose a Friend type outside of the Public class
'Form2'."

How can I resolve it?

Thanks again.
"Larry Serflaten" wrote:

"vvenk" <vv***@discussions.microsoft.com> wrote

I have two forms, FormA and FormB. FormA opens FormB. FormB needs to execute
a public method on FormA.

<...>
Sub doSomething()
MyParentForm.ExecuteFunction
End Sub

So, in other words, how can I generalize it so the parameter can be any of
the form classes that will have a public method ExecuteFunction?

There are two general purpose ways to handle that, using events, or using interfaces.

Using events means that any form that wants to, can declare FormB WithEvents
such that FormB will raise the event for the parent form to act on. The parent
would not be required to listen for events, even while formB raises them as scheduled.

If the decision to act on FormB's event is supposed to be in the parent form, that
would be the way to go. If FormB requires that there be a routine to call in the
parent form, then use an interface.

Using interfaces means you declare an interface with the required method, and force
all callers to implement that interface to show FormB:
Private MyParentForm as IParentInterface
Public Sub New(psForm as IParentInterface)
...
...
MyParentForm = psForm
End Sub

Sub doSomething()
MyParentForm.ExecuteFunction
End Sub
That would assume you've declared an interface somewhere
(in a module perhaps):

Public Interface IParentInterface
Sub ExecuteFunction()
End Interface

And any form that uses FormB must implement that interface:

Public Class FormA
Inherits System.Windows.Forms.Form
Implements IParentInterface

'... <rest of form code>

Public Sub ExecuteFunction() Implements IParentInterface.ExecuteFunction
' FormB callback function goes here
End Sub

End Class
The calling syntax would be similar to what you are probably already
using:

Dim dialog As FormB = New FormB(Me)
dialog.Show()
HTH
LFS

Nov 21 '05 #6

"vvenk" <vv***@discussions.microsoft.com> wrote

It almost worked but I get an error at compilation:

On FormB's Public New method:

Public Sub New(ByVal psForm As IParentFormDataGridSearchInterface)

it says "'psForm' cannot expose a Friend type outside of the Public class
'Form2'."

How can I resolve it?


For use in your own application, simply declare the New sub as Friend, instead of Public.

Friend Sub New(ByVal psForm As IParentFormDataGridSearchInterface)

LFS

Nov 21 '05 #7
Larry:

Thank you once again for your prompt reply and invaluable assistance.

Venki

"Larry Serflaten" wrote:

"vvenk" <vv***@discussions.microsoft.com> wrote

It almost worked but I get an error at compilation:

On FormB's Public New method:

Public Sub New(ByVal psForm As IParentFormDataGridSearchInterface)

it says "'psForm' cannot expose a Friend type outside of the Public class
'Form2'."

How can I resolve it?


For use in your own application, simply declare the New sub as Friend, instead of Public.

Friend Sub New(ByVal psForm As IParentFormDataGridSearchInterface)

LFS

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David M. Karr | last post by:
I've been asked to help debug a complex problem involving inter-frame references, so I just want to understand the elements involved with this. Apparently, there is a page with multiple frames,...
4
by: Frank Meng | last post by:
Hi. I am trying a csharp sample from http://www.codeproject.com/csharp/socketsincs.asp . (Sorry I didn't post all the source codes here, please get the codes from above link if you want to try)....
4
by: Viper Venom | last post by:
Dear All: I am trying to write an application that consist 2 executables 1) Server.exe 2) Client.exe I start the server.exe first and then start the two client exe by code and kill both of...
7
by: A.M | last post by:
Hi, What is the best way to implemet Inter Process Communication in .NET ? I developed two programs and I want to have them talk to each other. Thanks, Alan
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
6
by: les | last post by:
Here's a class which uses 2.0 generics to implement an inter-thread message queue in C#. Any number of threads can post and read from the queue simultaneously, and the message object can be any...
5
by: Joseph Geretz | last post by:
I need to communicate between two applications. The legacy application is in VB6. New development is in C#. Here's the scenario: The VB6 app will be pumping document files into a folder. We'll be...
0
by: Hugo Ferreira | last post by:
Hi everyone! Here's the current scenario: I have a program in Python that computes something very fast (<1s), but it takes a considerable amount of time to read the startup data (>90s). Since...
1
by: Laurence | last post by:
Hi folks, As I konw: database partition (aka data partition?), the database can span multiple machines; table partition, the data within a table can seperate by certain condition. How about...
0
by: dantz | last post by:
After reading all of the materials in msdn about interprocess communication now I am confused. I hope someone can give me some enlightment. I am developing a multithreaded client-server...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.