-
withevents
Hi,
i am translating some code from vb.net to c# and am having trouble with the 'withevents' declaration of a variable. For example how do i declare this in c#
Code:
Dim WithEvents myObj as Outlook.Application
'the event is then
Public sub MailSend(byval item as object, byref cancel as boolean) handles myObj.Itemsend
End sub
many thanks if you can help
nick
-
Outlook.Application myObj = new Outlook.Application();
Somewhere in a method (load, constructor, etc), place something like this..(exact code might be a little off, but the idea is the same) You have to subscribe to the event:
public MyConstructor
{
myObj.ItemSend += new ItemSend(MailSend);
}
public void MailSend(object item, boolean cancel)
{
//Code here.
}
-
thanks. moving from vb.net to c# is a little more tricky than i expected!
Cheers
Nick
-
Remember, the VS.NET IDE will help you out with these if you start typing it, you will notice little tooltip windows. They start saying press tab to fill in, then press tab again to create the stub. So, when you create them, it is pretty easy.