-
Jul 7th, 2016, 01:27 AM
#1
Thread Starter
Member
Add event handler for outside DLL?
Hi, I got many helps from here however I could not provide many help to others 'cause I'm very newbie.
Here is the problem. I know how can I set custom event handler from local form and others.
I made specific DLL Form which is made by Visual C#, which has certain "public" TextBox so I can see it's value
from my main VB.net program.
Problem is, I want add "TextChanged" event handler for this TextBox from DLL, it is easy to set by C#:
Code:
// Declare using my custom DLL
using MyDLL;
// Declare new instance for custom DLL (it is oviously Form DLL)
static MyDLLClass SubForm = new MyDLLClass();
// I can easly add this eventhandler for DLL's TextBox which name is "EventBox"
SubForm.EventBox.TextChanged += new EventHandler(SubEventHandler)
private void SubEventHandler(object sender, EventArgs e)
{ .... }
So, now I can handel and communicate from main application to custom DLL.
As soon as there is text entered on DLL's EventBox textbox, main app can catch it and fire
my own codes.
And now, I want use this DLL for my VB.net project.
Code:
' Declare using my custom DLL
Import MyDLL
' Declare new instance for custom DLL (Same as C#)
Public SubForm as MyDLLClass = new MyDLLClass()
' I want add custom Event Handler for this:
AddHandler SubForm.EventBox.TextChanged, AddressOf SubEventHandler
Private Sub CAMEventHandler(sender As Object, e As EventArgs)
...
End Sub
I belive this would work but it isn't.
There is no error whatsoever when I build project. Run, show and hide DLL form, and it's functions
are work perfectly but only not fire event handler.
Is there any way to do it? Please teach me the way, masters.
Thanks in advance!
-
Jul 7th, 2016, 02:14 AM
#2
Re: Add event handler for outside DLL?
Reading fail. Let's look at your C# code:
Code:
// Declare using my custom DLL
using MyDLL;
// Declare new instance for custom DLL (it is oviously Form DLL)
static MyDLLClass SubForm = new MyDLLClass();
// I can easly add this eventhandler for DLL's TextBox which name is "EventBox"
SubForm.EventBox.TextChanged += new EventHandler(SubEventHandler)
private void SubEventHandler(object sender, EventArgs e)
{ .... }
Now let's look at your VB code:
Code:
' Declare using my custom DLL
Import MyDLL
' Declare new instance for custom DLL (Same as C#)
Public SubForm as MyDLLClass = new MyDLLClass()
' I want add custom Event Handler for this:
AddHandler SubForm.EventBox.TextChanged, AddressOf SubEventHandler
Private Sub CAMEventHandler(sender As Object, e As EventArgs)
...
End Sub
If you tell it to invoke a method named 'SubEventHandler' then don't be surprised when it doesn't invoke a method named 'CAMEventHandler'.
-
Jul 7th, 2016, 02:16 AM
#3
Re: Add event handler for outside DLL?
By the way, you have declared 'SubForm' as 'static' in your C# code so, to be consistent, it should be declared 'Shared' in your VB code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|