Custom Save button that recognizes the form it is on?

General Fear

Member
Joined
Dec 22, 2012
Messages
12
Programming Experience
10+
I am using VB 2010.

I wanted to put the code below into a save custom control. The problem is that how do I get a custom control to recognize the form the custom control save button sits on? Is it possible to have the code below in a button custom class? If so it would be good because the company will have a "universal save checking" as a default behavior. Our checking occurs when the user leaves the control.

Code:


Dim ctrl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.

Do Until ctrl Is Nothing 'Use ctrl here.

If (TypeOf ctrl Is clsTextBox) Then
Dim mtb As clsTextBox = CType(ctrl, clsTextBox)

mtb.Focus()
SendKeys.SendWait("{TAB}")

If Not mtb.IsValidated Then
mtb.Focus()
Exit Do
End If

End If

ctrl = Me.GetNextControl(ctrl, True) 'Get the next control in the tab order.
Loop
 
Assuming the saving code is inside the button .Click event handler (which it should be, or should be called from...), cast the sender parameter to type Button or Control and use its .FindForm() method for a reference to the button's parent form.

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim ParentForm As Form = CType(sender, Button).FindForm()
 
Back
Top