I think I got it working! Here's what I did:
1) From my C# class, I declared a delegate variable, like so:
public partial class DelegateForm : Form
{
Delegate vbDelegate;
...
2) Now I implemented a C# method that takes a vb delegate as a
parameter. This method
gets called from VB:
public void exportDelegate(Delegate AVBDelegate)
{
vbDelegate = AVBDelegate;
}
3) Now that we have the delegate instance in place, we can invoke the
vb method *through* it. We can now
send the textBox value from C# to the Listbox found in the VB
form:
private void btnSendToVB_Click(object sender, EventArgs e)
{
vbDelegate.DynamicInvoke(textBox.Text);
}
On Nov 24, 5:55 pm, Benj Nunez <[EMAIL PROTECTED]> wrote:
> Hello experts,
>
> Is it possible to call avbdelegatein C#? I have a samplevbcode
> that looks like this:
>
> 1) first I declared adelegate
>
> PublicDelegateSub MessageDelegate(ByVal MsgString As String)
>
> 2) then the actual method:
>
> Public Sub addToList(ByVal MsgString As String)
> ListBox.Items.Add(MsgString)
> End Sub
>
> 3) then on my button click event I did this:
>
> Private Sub btnAddItems_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnAddItems.Click
> Dim localEntry As New MessageDelegate(AddressOf addToList)
> localEntry.Invoke(txtLocal.Text.Trim())
> End Sub
>
> What I want to do now is to somehow "export" the localEntry variable
> to my c# code (a *.dll) which looks like this:
>
> public void exportDelegate(DelegateAVBDelegate)
> {
> if (AVBDelegate != null)
> {
> // what should I type here?
> }
> }
>
> I learned that to use delegates you use Invoke(). I just found out
> that there's a method called "DynamicInvoke". I tried to use that in
> the C# side of the code but got a runtime exception.
> Forgive me for my ignorance. I just don't have an idea yet of what it
> does. :)
>
> Can someone help? Thanks in advance!
>
> Benj