|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Capture events for a control arrayI have 80 textboxes on my form that I want to capture the focus event and the
validating event. When someone enters any textbox, I want to capture the current value of textbox in a variable then on the validate event check the new value to see if there is a change, and if changed, set the background of the control to a different color to indicate a change. I can do this for all 80 textboxes, but it would be nice to have these events watch all textboxes (similiar to the old control array in VB). Anyone have any suggestions. On 2009-07-09, John Wright <JohnWri***@discussions.microsoft.com> wrote:
> I have 80 textboxes on my form that I want to capture the focus event and the You can attache the same event to multiple textboxes..> validating event. When someone enters any textbox, I want to capture the > current value of textbox in a variable then on the validate event check the > new value to see if there is a change, and if changed, set the background of > the control to a different color to indicate a change. I can do this for all > 80 textboxes, but it would be nice to have these events watch all textboxes > (similiar to the old control array in VB). Anyone have any suggestions. Just select the ones you want, go to the properties window, got to the events tab and then add the event procedure you want to handle.... Option Explicit On Option Strict On Public Class Form1 Private Sub TextBoxes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged, TextBox2.TextChanged, TextBox1.TextChanged Dim tb As TextBox = TryCast(sender, TextBox) If tb IsNot Nothing Then MessageBox.Show(tb.Name) End If End Sub End Class You can do it manually, it's just adding more controls to the handles clause :) The sender parameter will be the actual textbox that raised the event. So, in the above example I simply cast it to a textbox.-- Tom Shelton
Using Special Folders in App.Config
inputbox Connection limit Mult-Threading and TraceListeners How Do I Find MyApplication Events? Seperating Debug and Trace Output Get average of a row Running progress indicator in different thread to UI thread Have thread end if not finished in X seconds How To :App.Config |
|||||||||||||||||||||||