Expanding on this deriving from System.EventArgs will give you the
opportunity to store the scanned data in the event argument thus:
public class ScannerArgs : System.EventArgs
{
public readonly string Data;
public ResponseArgs(string data)
{
this.data = data;
}
}
public delegate void ScannedEventHandler(object sender, ScannerArgs scan);
so now in your event hander you can access the data via the event object
using e.Data
"Alex Yakhnin [MVP]" <(E-Mail Removed)> wrote in message
news:25486C86-7D9D-4301-87EA-(E-Mail Removed)...
> You should declare your own delegate type, something like that:
>
> public delegate void ScannedEventHandler(object sender, string
> barcodeData);
>
> and then in your ScanEngine class you'd declare your event as
>
> public event ScannedEventHandler Scanned;
>
> HTH... Alex
>
> --
> Alex Yakhnin, .NET CF MVP
> www.intelliprog.com
> www.opennetcf.org
>
>
> "Dan Bass" wrote:
>
>> I'm writing a scanner application (C# / .Net CF) where I have one
>> scanner
>> object (singleton) that hooks into the scan engine drivers.
>>
>> There is scanner event for a successful scan, that passes through the
>> scanned data to an event handler. From here I need to pass this
>> information
>> back to my form, so what I've done is to create another event handler in
>> the
>> form, which is fired from the event handler in my scanner class.
>>
>> The Form declaration of this object looks like this:
>>
>> Is this ok?
>> Is this considered good practice or is there a blatantly obvious and much
>> better way of doing this?
>>
>> Below is the code that's relevant:
>>
>> // ----------------------------------------------------------
>> //
>> // myForm snippet
>> //
>>
>> ScanEngine scanner;
>>
>> private void myForm_Load(object sender, System.EventArgs e)
>> {
>> scanner = new ScanEngine();
>> scanner.StartScan();
>> scanner.Scanned += new EventHandler(BarcodeRead);
>> }
>>
>> private void FormPut_Closing(object sender,
>> System.ComponentModel.CancelEventArgs e)
>> {
>> if ( scanner != null )
>> {
>> scanner.StopScan();
>> scanner.Scanned -= new EventHandler(BarcodeRead);
>> scanner = null;
>> }
>> }
>>
>> void BarcodeRead(object sender, System.EventArgs e)
>> {
>> if ( scanner != null )
>> {
>> string barData = scanner.BarcodeData;
>>
>> // do stuff here
>>
>> }
>> }
>>
>> // ----------------------------------------------------------
>> //
>> // ScanEngine snippet
>> //
>>
>>
>> private string barData = "";
>> public event System.EventHandler Scanned;
>>
>> // called when a scan occurs
>> protected virtual void OnScanned(EventArgs e)
>> {
>> if (Scanned != null)
>> Scanned(this, e);
>> }
>>
>> public string BarcodeData
>> {
>> get
>> {
>> return barData;
>> }
>> }
>>
>>
>>
>>
>>