Results 1 to 4 of 4

Thread: withevents

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870

    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.
    }

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    thanks. moving from vb.net to c# is a little more tricky than i expected!

    Cheers
    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width