Click here to Skip to main content
14,265,815 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a Login form and the user logs in by swiping their RFID Tag.
I also have a section in the application (win Forms) where an Admin user can add aditional users to the system and assign them a tag(for login)

My TagRead event is triggered in Login, and I see no point in closing the connection to the reader after login just to open one again on another form in the same application.

Problem is on my AddUser form when I scan the tag to assing to the user the TagRead Event is triggered on the login form (where the connection was established)

So what do I do?
Try to listen to the event finishing on the login form and then read tag data on AddUser? can I trigger the read event to happen in AddUser form?

What I have tried:

I have read up on Delegates and tried creating a delegate on the login form for the TagRead event and then assign that event to a method in the AddUser form

LOGIN_Frm
public delegate void EventHandler(object sender, TagReadEventArgs e);
        EventHandler EventHandlerDelegate;
         public event EventHandler Read
        {
            add
            {
                this.EventHandlerDelegate += value;
            }
            remove
            {
                this.EventHandlerDelegate -= value;
            }
        }
private void Reader_OnTagRead(object sender, TagReadEventArgs e)
        {
            tags.Add(e.RrfidTag);
            BindList();  
            
 if (this.EventHandlerDelegate != null)
            {
                
                EventArgs e2 = new EventArgs(); // pass along this new EventArgs object
                object[] args = new object[] { sender, e };

               
                foreach (Delegate handler in this.EventHandlerDelegate.GetInvocationList())
                {
                    handler.DynamicInvoke(args);
                    if (e.Handled)
                        break;
                }
            }
        }


AddUser frm
Login frmLogin = new Login();
 this.frmLogin.Read += new ControlTestApp.Login.EventHandler(this.Reader_OnTagRead);
 private void Reader_OnTagRead(object sender, TagReadEventArgs e)
        {
           //Do stuff here to get tag info

        }


but this still does not trigger the event/method in the Add User form


I dont have an event on AddUser that can trigger the event on Login I kind of either need Login to say "hey I just read a tag" or I need AddUser to say "have you read a tag yet? how about now?"
Posted
Comments
nitrous_007 20-May-17 22:58pm
   
Hi,
I am getting confused by the description of your issue. Remove everything about your particular application- remember you don't care to tell us about that. Stick to description of the code only. For example. I have a Form1 which opens Form2. When I click a button on Form2, I want it to trigger an even in Form1 etc etc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100