hi,. i have the method newform. now when i add a form , i want to add an event the form disposed method to all forms that i create,. i do not want to rewrite the code each time i have to create a form., what am i looking at how i attach an event to any form in vb
Public
Sub NewForm(ByRef i As Form)Forms.Add(i)
i.MdiParent =
Mem_ChildFormNumber += 1
i.Show()
End Sub Public Sub Form_Disposed(ByRef f As Form) - - -- something similar but general.,Forms.Remove(f)
myNavigator.BindingSource =
Nothing End Sub
events
JAAmutio
Artie Sluka
RC COLA
The following is a simple example of declaring and using a delegate.
Imports System Public Class SamplesDelegate ' Declares a delegate for a method that takes in an int and returns a String. Delegate Function myMethodDelegate(myInt As Integer) As [String] ' Defines some methods to which the delegate can point. Public Class mySampleClass ' Defines an instance method. Public Function myStringMethod(myInt As Integer) As [String] If myInt > 0 Then Return "positive" End If If myInt < 0 Then Return "negative" End If Return "zero" End Function 'myStringMethod ' Defines a static method. Public Shared Function mySignMethod(myInt As Integer) As [String] If myInt > 0 Then Return "+" End If If myInt < 0 Then Return "-" End If Return "" End Function 'mySignMethod End Class 'mySampleClass Public Shared Sub Main() ' Creates one delegate for each method. Dim mySC As New mySampleClass() Dim myD1 As New myMethodDelegate(AddressOf mySC.myStringMethod) Dim myD2 As New myMethodDelegate(AddressOf mySampleClass.mySignMethod) ' Invokes the delegates. Console.WriteLine("{0} is {1}; use the sign ""{2}"".", 5, myD1(5), myD2(5)) Console.WriteLine("{0} is {1}; use the sign ""{2}"".", - 3, myD1(- 3), myD2(- 3)) Console.WriteLine("{0} is {1}; use the sign ""{2}"".", 0, myD1(0), myD2(0)) End Sub 'Main End Class 'SamplesDelegateROLIVIER
F.Show()
AddHandler F.FormClosing, AddressOf Form_Closing AddHandler F.LostFocus, AddressOf Form_LostFocus End Sub Public Sub Form_LostFocus(ByVal s As Object, ByVal e As System.EventArgs) Trymynav.BindingSource =
Nothing Catch ex As Exception End Try End Sub Public Sub Form_Closing(ByVal s As Object, ByVal e As FormClosingEventArgs)mynav.BindingSource =
Nothing End Subfor now i have this,, and it doesnt seem to work nicely.
Alexei Moudretsov
How do you difine the type of FormClosing and LostFocus I think they should be like
Delegate Function ClosingDelegate(ByVal s As Object, ByVal e As FormClosingEventArgs) As [String]
Delegate Function LostFocusDelegate(ByVal s As Object, ByVal e As System.EventArgs) As [String]
Dim FormClosingAs New ClosingDelegate(AddressOf Form_Closing)
Dim LostFocus As New LostFocusDelegate(AddressOf Form_LostFocus)