Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delegate
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
00765008
Message ID:
00765060
Vues:
14
Randy,

One difference between C# and VB .NET is the VB .NET does not allow you to have events that return values. To get around this you need to change the delegate to a Sub instead of a Function.

>Hello all, I am converting some C# code to VB. I am having a problem with the code below. The design time debugger underlines the BeforeMessageEventHandler after Public Event. The error is
>Events cannot be declared with a delegate type that has a return type.
>Is the conversion wrong or does the code only work for C#. Thanks for the help.
>
>
>'VB Code
>Imports System
>Imports Microsoft.WindowsCE.Forms
>
>Namespace Corrigo.CorrigoNet.CorrigoNetToGo
>
> Public Class clsMessageWindow
>
> ' Summary description - MessageWindow.
>
> Inherits MessageWindow
>
> Public Sub New()
> End Sub 'New
>
> Delegate Function BeforeMessageEventHandler(ByRef msg As Message) As Boolean
> Delegate Sub AfterMessageEventHandler(ByRef msg As Message)
>
> Public Event BeforeMessageEvent As BeforeMessageEventHandler
> Public Event AfterMessageEvent As AfterMessageEventHandler
>
>
> Protected Overrides Sub WndProc(ByRef m As Message)
> If Not (BeforeMessageEvent Is Nothing) And BeforeMessageEvent(m) Then
> Return
> End If
> MyBase.WndProc(m)
> RaiseEvent AfterMessageEvent(m)
> End Sub 'WndProc
>
> End Class
>
>End Namespace 'Corrigo.CorrigoNet.CorrigoNetToGo
>
>
>'C# code
>using System;
>using Microsoft.WindowsCE.Forms;
>
>namespace Corrigo.CorrigoNet.CorrigoNetToGo
>{
> ///
> /// Summary description for MyMessageWindow.
> ///

> public class MyMessageWindow: MessageWindow
> {
> public MyMessageWindow()
> {
> }
>
> public delegate bool BeforeMessageEventHandler(ref Message msg);
> public delegate void AfterMessageEventHandler(ref Message msg);
> public event BeforeMessageEventHandler BeforeMessageEvent;
> public event AfterMessageEventHandler AfterMessageEvent;
>
> protected override void WndProc(ref Message m)
> {
> if ( BeforeMessageEvent != null && BeforeMessageEvent(ref m) )
> return;
> base.WndProc (ref m);
> AfterMessageEvent(ref m);
> }
>
> }
>}
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform