473,383 Members | 1,805 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,383 software developers and data experts.

Help on Event with Interface ?????

Dear all,

I have one assembly named UserInfo which contains a form1
and a class1
I have a main application wich refer to the UserInfo
library by using the import keyword or adding reference to
my project.

From my main application, I would like to be informed when
the Button_click event of my form1 in UserInfo library is
fire.

Is there a safe way to retrive that event inside my
application through an interface?

thanks fo your answer
regards
serge
Nov 19 '05 #1
4 1785
"Serge Calderara" <se*************@maillefer.net> schrieb
I have one assembly named UserInfo which contains a form1
and a class1
I have a main application wich refer to the UserInfo
library by using the import keyword or adding reference to
my project.

From my main application, I would like to be informed when
the Button_click event of my form1 in UserInfo library is
fire.

Is there a safe way to retrive that event inside my
application through an interface?


Is Form1 Public or Friend? If Public, change the modifier of the button from
Friend to Public. Then you can handle the Button's click event.

If you don't wanna make the Form or the Button public, you could implement a
public interface. Example:

public interface IWhatever
Event Buttonclicked
end interface

Form1:
implements IWhatever
'...
Public Event ButtonClicked() Implements IWhatever.ButtonClicked
'...
sub button_click
raiseevent ButtonClicked
end sub

Now you can expos the Form object from the DLL via a reference of Type
IWhatever.
But the best solution always depends on the purpose...
--
Armin
Nov 19 '05 #2
Thanks for your reply..

My button in the forms a declared as follow, which is the default, I
took it as it is from the wizard:

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
in that declaration all events have by default to the scope of the
assembly with the keyword Friend. By experience I used to never change
any decalaration generated by a wizard, I use to get problem with that
in the past whne I do it.

And in that present case chech the commnet that is mentionned just
before the declaration of the button event.
it is mentionned DO NOT MODIFY uising the code editor.

Thats the reason why I was thinking of an other way of caching event of
the form outsite its own assembly.

By using the interface I was thinking on having all needed information
deliver from on point without changing any thing in the form.

Does this help you to tell me what is the best way ?

thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3
"calderara serge" <an*******@devdex.com> schrieb
And in that present case chech the commnet that is mentionned just
before the declaration of the button event.
it is mentionned DO NOT MODIFY uising the code editor.
You can modify it using the form designer. In the property window, set the
"modifiers" to public.

Thats the reason why I was thinking of an other way of caching event
of the form outsite its own assembly.

By using the interface I was thinking on having all needed
information deliver from on point without changing any thing in the
form.

Does this help you to tell me what is the best way ?


Is making the Button public sufficient to solve the problem?
--
Armin

Nov 19 '05 #4
The answer is yes. I ran into this a couple of weeks ago and was helped out
by one of the gurus:

1) In my assembly with the main application (the one being imported):

Public Interface IHandleFTPReader
Sub AddHandlers(ByVal cl As FTPFileReader.FTPReader)
Sub RemoveHandlers(ByVal cl As FTPFileReader.FTPReader)
End Interface

Private ReadOnly m_Handler As IHandleFTPReader

Public Delegate Sub MessageToFormEventHandler(ByVal sender As Object, ByVal
e As MessageToFormEventArgs)
Public Event Message As MessageToFormEventHandler

Protected Overridable Sub OnMessage(ByVal e As MessageToFormEventArgs)
RaiseEvent Message(Me, e)
End Sub

Public Sub New(ByVal handler As IHandleFTPReader)
''add the handlers
m_Handler = handler
m_Handler.AddHandlers(Me)
End Sub

1a) event args

Public Class MessageToFormEventArgs
Inherits EventArgs
Private ms_Message As String
Public Sub New(ByVal sMessage As String)
ms_Message = sMessage
End Sub
Public ReadOnly Property Message() As String
Get
Return ms_Message
End Get
End Property
End Class

1b) to raise the event:
dim evt as New MessageToFormEventArgs("ERROR: blah ...")
OnMessage(evt)

2) In the form application:

Implements IHandleFTPReader

Public Sub AddHandlers(ByVal cl As yourproject1.yourproject1class)
Implements IHandleFTPReader.AddHandlers
AddHandler cl.Message, AddressOf MessageReceivedFromClass
End Sub

Private Sub MessageReceived(ByVal sender As Object, ByVal e As
projectnamegoeshere.MessageToFormEventArgs)
''do whatever you want with the message ...
End Sub
Hope this helps,
Timbo

"Serge Calderara" <se*************@maillefer.net> wrote in message
news:03****************************@phx.gbl...
Dear all,

I have one assembly named UserInfo which contains a form1
and a class1
I have a main application wich refer to the UserInfo
library by using the import keyword or adding reference to
my project.

From my main application, I would like to be informed when
the Button_click event of my form1 in UserInfo library is
fire.

Is there a safe way to retrive that event inside my
application through an interface?

thanks fo your answer
regards
serge

Nov 19 '05 #5

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

Similar topics

7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
6
by: Charles Law | last post by:
I have a class, which implements an interface. Let's say, that the interface looks something like Public Interface IEventSinks Sub ValueChanged(sender As Object, e As ValueChangedEventArgs) Sub...
1
by: Hardeek Thakkar | last post by:
Dear friends, In my current project I am using the CustomCollections with the help of BindingList<Tgeneric class to store the database records instead using DataSet objects as offline database...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
11
by: Wayne Pedersen | last post by:
Need some help - and I may be doing this wrong, so please correct and suggest! I'm learning the MVP method, which I seem to have a good grasp of. Now I am trying something a bit more advanced. ...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.