Click here to Skip to main content
15,891,905 members
Articles / Desktop Programming / Windows Forms

Form Changed Control

Rate me:
Please Sign up or sign in to vote.
4.79/5 (13 votes)
26 May 2008CPOL2 min read 91.2K   1.9K   80  
A component that allows you to monitor all the controls on the form and list any that have changed (for dirty checking)
Public Class Form1

    Private Sub Button_Reset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Reset.Click
        Me.FormChangedComponent1.ResetDirtyFlags()
    End Sub




    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()


    End Sub



    Private Sub Button_WhatChanged_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_WhatChanged.Click

        Dim s As New System.Text.StringBuilder
        For Each f As Control In Me.FormChangedComponent1.ControlsThatHaveChanged
            s.AppendLine(f.Name)
        Next
        If s.Length > 0 Then
            MessageBox.Show(s.ToString, "Controls that have changed", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("Nothing has changed", "Controls that have changed", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

    End Sub

    Private Sub FormChangedComponent1_FormControlChanged(ByVal sender As Object, ByVal e As FormChangedEventArgs) Handles FormChangedComponent1.FormControlChanged
        If TypeOf e.ControlChanged Is TextBox Then
            If e.Changed Then
                e.ControlChanged.BackColor = Color.Yellow
            Else
                e.ControlChanged.BackColor = Color.White
            End If
        End If
    End Sub
End Class

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)


Written By
Software Developer
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

Comments and Discussions