473,513 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control delegate in an Interface

Hi,
I have a couple of forms on my client application that use an
asyncronous tcp client to send and recieve data from a server
application.
On each of these forms, i have a Listbox which i would like to add
status information to, like,

"Connected to server"
"Details Sent"
"Details Received"

Is it possible to have my forms implement an interface that includes a
generic delegate such as

"void AddStatusString(String s)"

where i pass the message s from the tcp client to my form's listbox?

This is sending me a bit screwy because i cant get my head around
exactly what needs to be in the interface. I know it can't be "void
AddStatusString(String s)" because this is the function in my form that
is Invoked BY a delegate, if you get my meaning.

Many thanks in advance,
James Randle.

Aug 3 '06 #1
3 1326
pigeonrandle <pi**********@hotmail.comwrote:
Hi,
I have a couple of forms on my client application that use an
asyncronous tcp client to send and recieve data from a server
application.
On each of these forms, i have a Listbox which i would like to add
status information to, like,

"Connected to server"
"Details Sent"
"Details Received"

Is it possible to have my forms implement an interface that includes a
generic delegate such as

"void AddStatusString(String s)"

where i pass the message s from the tcp client to my form's listbox?

This is sending me a bit screwy because i cant get my head around
exactly what needs to be in the interface. I know it can't be "void
AddStatusString(String s)" because this is the function in my form that
is Invoked BY a delegate, if you get my meaning.
I'm not sure I see why a delegate is needed. If you implement the
interface, you just write a method AddStatusString which is implemented
by adding the given string to the listbox - why do you need delegates?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #2
pigeonrandle <pi**********@hotmail.comwrote:
Hi,
I have a couple of forms on my client application that use an
asyncronous tcp client to send and recieve data from a server
application.
On each of these forms, i have a Listbox which i would like to add
status information to, like,

"Connected to server"
"Details Sent"
"Details Received"

Is it possible to have my forms implement an interface that includes a
generic delegate such as

"void AddStatusString(String s)"
No interface needed.
public delegate void AddStatusStringHandler(String s);

public class TcpServer
{
public event AddStatusStringHandler AddStatusStringEvent;
}

public class ClientForm : Form
{
public ClientForm(TcpServer tcpServer)
{
// form initialization code skipped

tcpServer += new AddStatusStringHandler(AddStatusString);
}

private AddStatusString(String s)
{
// add string to list box
}
}
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Aug 3 '06 #3
Thomas T. Veldhouse <ve*****@yahoo.comwrote:
>

public delegate void AddStatusStringHandler(String s);

public class TcpServer
{
public event AddStatusStringHandler AddStatusStringEvent;
}
Granted ... the name of the delegate and event are horrendous in my example
:-)

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Aug 3 '06 #4

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

Similar topics

1
2488
by: Liz | last post by:
As a newbie I have been trying to set up an event handler in my user-defined control to trigger an event in my form when lblSelectedClient.Text changes. I get an error on my event definition...
1
4770
by: Nadav | last post by:
Hi, I Wonder... Can a server-side class exposed through remoting expose a delegate? In other words: can a client set a server-side delegate that in-turn will be asynchronously called from the...
6
12261
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
15
26487
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
4
1564
by: Steven Cummings | last post by:
Hello, I'm currently developing on a large project where several assemblies build into DLLs that support the final .NET EXE. The original plan was to implement the project in VB.NET, so the EXE...
3
2667
by: Asaf | last post by:
Hi, We have a VB6 application that needs to use a new control written in ..NET v1.1 C#, imported as a COM control. We have tried adding the C# control to the VB6 control both dynamically (using...
5
29789
by: atwomey | last post by:
When I try and place a delegate in an interface, like this : public interface ITest { double foo(); delegate void bar(); } I get an error "delegates cannot declare types". What is it about a...
3
11539
by: steve | last post by:
Hi all, I want to be able to hirearchally define event delegate (declarations) WITHIN interfaces. Unfortunatelly C# 1 doesn't appear to support it. How does the following look as a...
0
2473
by: jonathan.beckett | last post by:
I have been working on a client project recently that is using winforms ..NET user controls within web pages in Internet Explorer, and need to find out how to make the user control communicate back...
0
7260
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
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7537
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
7525
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
5685
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
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.