Click here to Skip to main content
15,885,004 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Pass value between forms using events

Rate me:
Please Sign up or sign in to vote.
3.11/5 (5 votes)
5 Aug 2010CPOL 11.6K   5
Alternatively, you could just expose some public properties and raise a standard event. In the event handler you could read the properties as usual, without having to define a new EventArgs.Also if you really need to set properties on the owner, you again could just expose some public...
Alternatively, you could just expose some public properties and raise a standard event. In the event handler you could read the properties as usual, without having to define a new EventArgs.

Also if you really need to set properties on the owner, you again could just expose some public properties and then pass the owner as an argument when calling ShowDialog(), requiring no events at all.

Which is best depends on the situation, but usually I would avoid defining a new EventArgs just to pass text around.

License

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


Written By
Engineer NAVER LABS Europe
France France
Computer and technology enthusiast, interested in artificial intelligence and image processing. Has a Master's degree on Computer Science specialized on Image and Signal Processing, with expertise on Machine Learning, Computer Vision, Pattern Recognition and Data Mining systems. Author of the Accord.NET Framework for developing scientific computing applications.

If you would like to hire good developers to build your dream application, please check out DaitanGroup, one of the top outsourcing companies in Brazil. This company, located in Brazil's Sillicon Valley but with US-based offices, has huge experience developing telecommunications software for large and small companies worldwide.

Comments and Discussions

 
GeneralReason for my vote of 2 While it works in principle, it tigh... Pin
jim lahey1-Feb-12 23:35
jim lahey1-Feb-12 23:35 
GeneralReason for my vote of 1 noob Pin
Barbo1-Sep-10 23:08
Barbo1-Sep-10 23:08 
GeneralIt all depends. If all you have is a form which asks for use... Pin
César de Souza7-Aug-10 5:03
professionalCésar de Souza7-Aug-10 5:03 
GeneralReason for my vote of 3 See my comments below. Pin
DaveyM697-Aug-10 4:44
professionalDaveyM697-Aug-10 4:44 
General1. Public properties in the object that raises an event is a... Pin
DaveyM697-Aug-10 4:43
professionalDaveyM697-Aug-10 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.