How to detect if user has made changes to a windows application in C#

Posted on 2012-09-02
Last Modified: 2012-09-03
Hi experts
I am developing a C# .NET 3.5 applications using Winform.

I wonder how to detect user has made any changes so that it will prompt the user to save settings before exiting from the application.

Thanks in advance.
Question by:dominicwong
    LVL 16

    Expert Comment

    by:Easwaran Paramasivam
    The idea is that whenever your change, say for example modify text in a textbox, in the respective event a global FLAG could be set. Say for example IsModified = true.
    Once user Save/Cancel then the flag should be reset IsModified = false.

    If IsModified = true and user tries to close the application, then the user could be prompted.

    Author Comment

    Thanks EaswaranP.
    But what if my application has hundreds of Controls such as Textbox, Combobox, checkbox, dgv, etc, it would be tedious to add a flag to every event handler.
    LVL 16

    Assisted Solution

    by:Easwaran Paramasivam
    If more controls then you could Implement Observer pattern.

    Please do refer above links. They could help you. Observer pattern in nothing but when event triggers it notifies others.

    Please google on the topic more to implement the same.

    This is the way you have to go.
    LVL 49

    Accepted Solution


    Author Closing Comment

    Thanks julianH and EaswaranP.
    These links are excellent references!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
    The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
    Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now