Glossary Item Box

PowerTCP SSL Sockets for .NET

Using Events When A Component Is Created Dynamically

If you are using the a PowerTCP component as a class (instead of adding it to the project as a component), and would like to use events, you must "wire-up" the event yourself. This topic addresses how to do this using either VB.NET or C#. Note: You do NOT need to "wire-up" the events yourself if you are dragging an instance of a PowerTCP component onto the form while using Visual Studio .NET. In this case all event subscription will be handled by the environment.

 

To use events when using a PowerTCP component as a class and creating a VB.NET Windows Application, use the following steps (steps for C# below).

  1. Start a new VB.NET project and add a PowerTCP component as a reference (see Creating Components Dynamically for information of how to do this). In this example, the Tcp component is used.
  2. Navigate to the View menu and then select Code to switch to code view.
  3. Create an instance of the Tcp class. Be sure to use the WithEvents keyword such as in the following:
    Private WithEvents Dart.PowerTCP.SslSockets.Tcp1 As New Dart.PowerTCP.SslSockets.Tcp()
    
  4. You must create a method that implements the appropriate delegate. The first step is to determine which event you would like to "wire-up". For the purposes of this walk-through, the EndSend event will be used, although other events would work in a similar manner.
  5. Navigate to the EndSend event in the Reference section.
  6. The syntax definition for the appropriate language specifies which delegate is implemented by the event. For example the VB.NET syntax for the EndSend event is:
    public Event EndSend As Dart.PowerTCP.SslSockets.SegmentEventHandler
    
    In other words, to "wire-up" the EndSend event, you must first create a method that implements the SegmentEventHandler delegate.
  7. Navigate to the reference listing for the SegmentEventHandler delegate. This listing will tell you what your event-handler method should look like. According to the SegmentEventHandler delegate, your method must accept two arguments (an object and an SegmentEventArgs object) and return nothing, so create a method that does this. This method should look similar to the following:
    Private Sub MyEndSendHandler(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.SegmentEventArgs)
       ' Write code to handle the event here.
    End Sub
    
  8. Finally, the event handler must "subscribe" to the event.  In VB.NET, this can simply be done by using the "Handles" keyword next to the event handler as such:
    Private Sub MyEndSendHandler(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.SegmentEventArgs) Handles Tcp1.EndSend
       ' Write code to handle the event here.
    End Sub
    
  9. Now the EndSend method can be used, and the EndSend event will be raised upon the completion of this method.

 

To use events when using a PowerTCP component as a reference and creating a C# Windows Application, use the following steps.

  1. Start a new C# project and add a PowerTCP component as a reference (see Creating Components Dynamically for information of how to do this. In this example, the Tcp component is used.
  2. Navigate to the View menu, and then select Code to switch to code view.
  3. Create an instance of the Tcp class such as:
    private Dart.PowerTCP.SslSockets.Tcp tcp1 = new Dart.PowerTCP.SslSockets.Tcp();
    
  4. Now you must create a method that implements the appropriate delegate. The first step is to determine which event you would like to "wire-up". For the purposes of this walk-through, the EndSend event will be used, although other events would work in a similar manner.
  5. Navigate to the EndSend event in the Reference section.
  6. The syntax definition for the appropriate language specifies which delegate is implemented by the event. For example the C# syntax for the EndSend event is:
    public event Dart.PowerTCP.SslSockets.SegmentEventHandler EndSend;
    
    In other words, to "wire-up" the EndSend event, you must first create a method that implements the SegmentEventHandler delegate.
  7. Navigate to the reference listing for the SegmentEventHandler delegate. This listing will tell you what your event-handler method should look like. According to the SegmentEventHandler delegate, your method must accept two arguments (an object and a SegmentEventArgs) and return void, so create a method that does this. This method should look similar to the following:
    private void MyEndSend(object sender, Dart.PowerTCP.SslSockets.SegmentEventArgs e)
    {
       // Write code to handle the event here.
    }
    
  8. Finally, the event handler must "subscribe" to the event. In C#, this can be done as such (put this code in your form initialization):
    tcp1.EndSend += new Dart.PowerTCP.SslSockets.SegmentEventHandler(this.MyEndSend);
    
  9. Now the EndSend method can be used, and the EndSend event will be raised upon the completion of this method.

 

In This Section

Creating a Project
This topic demonstrates how to create a new Windows project in Visual Studio .NET.
Placing Components on a Form
This topic demonstrates how to create and use a control using Visual Studio .NET.
Creating Components Dynamically
This topic demonstrates how to add a component as a reference using Visual Studio .NET.
Creating Custom Dlls
Discusses the steps required when creating a dll that uses a PowerTCP control.
Using Components Outside of Visual Studio
This topic discusses the use of the components without Visual Studio.
Using Events within the Visual Studio .NET Environment
Describes how to use PowerTCP events within the Visual Studio .NET environment.
Using Events when a Component is Created Dynamically
Describes the extra steps required to use events when using a PowerTCP component as a reference.

 

 


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.