Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2007, 05:14 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default raise event

Hallo,

I'm building a small app. In de mainform i have a public bool called hasChanged. I would like to raise an event when that bool changes. (becomes true or vice versa)
I have search the web about delegates en eventhandlers, but i can't find a solution to do so.

anybody?

thanks in advanced, Martijn

 
Old May 30th, 2007, 09:16 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Probably the best approach would be to use a public property instead of a public variable. This way you can program in what you need in the accessors (get/set). In the set block, you can check if the assigned value is different than the current value, and then raise the event (i.e. call the event delegate) if it's different. When you do this, consider that you might want to set the new value before you actually make the delegate call so that consumers of the class instance will see the new value instead of the old.

-Peter




Similar Threads
Thread Thread Starter Forum Replies Last Post
Raise Events Apocolypse2005 Visual Basic 2005 Basics 2 May 10th, 2008 12:43 PM
Raise an Error in dynamic SQL with Link Server bashiiui SQL Server 2000 7 May 2nd, 2007 04:10 AM
How to raise event in user control webpart... tqit ASP.NET 2.0 Basics 1 September 13th, 2006 04:37 AM
Raise Event From Dynamic Controls netwizard_01 ASP.NET 1.0 and 1.1 Basics 1 August 3rd, 2006 06:50 AM
Raise Event for Dynamically Added DropDownList DolphinBay ASP.NET 1.0 and 1.1 Professional 3 December 6th, 2005 02:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.