Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Form Changed Control

, 26 May 2008
A component that allows you to monitor all the controls on the form and list any that have changed (for dirty checking)
formchangecontroltest_csharp_src.zip
Form Change Control Test CSharp
bin
Debug
Properties
Settings.settings
formchangecontrol_src.zip
Form Change Control Test
Form Change Control Test
bin
Debug
Form Change Control Test.exe
Form Change Control Test.vbproj.user
My Project
Application.myapp
Settings.settings
Form Change Control Test.suo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Form_Change_Control_Test_CSharp
{
    public partial class Form_Changetest : Form
    {
        public Form_Changetest()
        {
            InitializeComponent();

            this.Button_Reset.Click += new EventHandler(Button_Reset_Click);
            this.Button_WhatChanged.Click += new EventHandler(Button_WhatChanged_Click);

            this.formChangedComponent1.MonitoredControlChanged += new FormChangedComponent.MonitoredControlChangedEventHandler(formChangedComponent1_MonitoredControlChanged); 

        }

        void formChangedComponent1_MonitoredControlChanged(object sender, FormChangedEventArgs e)
        {
            if (e.ControlChanged is TextBox)
            {
                if (e.Changed)
                {
                    e.ControlChanged.BackColor = Color.Yellow; 
                }
                else 
                {
                    e.ControlChanged.BackColor = Color.White;
                }
            }
        }


        void Button_WhatChanged_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder _ctlsOut = new StringBuilder();
            foreach (Control  ctl in this.formChangedComponent1.ControlsThatHaveChanged  )
            {
                _ctlsOut.AppendLine(ctl.Name); 
            }
            System.Windows.Forms.MessageBox.Show(_ctlsOut.ToString(), @"Controls that have changed");  
        }

        void Button_Reset_Click(object sender, EventArgs e)
        {
            this.formChangedComponent1.ResetDirtyFlags();
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

About the Author

Duncan Edwards Jones
Software Developer (Senior)
Ireland Ireland
C# / SQL Server developer
Microsoft MVP 2006, 2007
Visual Basic .NET
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 May 2008
Article Copyright 2007 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid