|
-
May 1st, 2008, 05:27 PM
#1
Thread Starter
PowerPoster
[RESOLVED] [2.0] C# Class -> Howto RaiseEvent VB-like
All,
Most of my work involves VB.*. I am familiar with defining a VB Class with a
VB Code:
Public Event thisEvent(args)
Now I am working with a C# Class, which is consumed by VB code. I need to make the C# Class "Raise an Event" which can be handled by the VB consumer code.
Here is a code snippet, of what I think I want to do:
Code:
namespace SNAPI_App
{
public partial class mainForm : Form
{
MotoSnapi.SnapiScanner scanner1;
MotoSnapi.SnapiScanner scanner2;
int status = 0; /* Return values of function calls */
static short[] paramsList /* Parameter information list */
= new short[SnapiDLL.MAX_PARAM_LEN];
int selectedScanner = 0;
static ArrayList scannerList = new ArrayList();
public mainForm()
{
Public Event thisEvent; // <- this doesn't work...
// ...
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
May 1st, 2008, 06:23 PM
#2
Thread Starter
PowerPoster
Re: [2.0] C# Class -> Howto RaiseEvent VB-like
OK I was able to find some sample code to help out, and I got it to work:
Code:
namespace SNAPI_App
{
public partial class mainForm : Form
{
//declaring the event handler delegate
public delegate void ButtonEventHandler(object source, int clickCount);
//declaring the event
public event ButtonEventHandler ButtonClick;
//Function to trigger the event
//This will be called when the user clicks the button
public void clicked(int count)
{
if (ButtonClick != null) ButtonClick(this, count);
}
//
public delegate void ScannerInput (object source, string strScanData);
public event ScannerInput ScanData;
public void scanned(string strInput)
{
if (ScanData != null) ScanData(this, strInput);
}
public mainForm()
{
InitializeComponent();
// ...
Now, from VB-land:
VB Code:
Imports SNAPI_App
Public Class Form1
Private WithEvents snapiApp As SNAPI_App.mainForm
' ...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
snapiApp = New SNAPI_App.mainForm
snapiApp.Show()
snapiApp.Visible = False
End Sub
Private Sub snapiApp_ScanData(ByVal source As Object, ByVal strScanData As String) Handles snapiApp.ScanData
MsgBox(strScanData)
End Sub
Last edited by Dave Sell; May 1st, 2008 at 06:26 PM.
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
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
|