Click here to Skip to main content
15,887,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I have project.

In my project I am creating new form at runtime.

When that new opened I want write some load event in that new form.


You people can explain me or give me the coding for that
Posted
Updated 9-Oct-10 12:59pm
v2

1 solution

Look at the following example code. A Form has a Button on it. The button when clicked, create a new form, attaches a handler to the Load event and then displays the new form.

The handler is fired and a message box with the new forms name is displayed;

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Create a new form
    Dim FormX As New Form
    FormX.Name = "SomeForm"
    AddHandler FormX.Load, AddressOf SomeHandlerFunction
    FormX.Show()
End Sub

Public Sub SomeHandlerFunction(ByVal sender As System.Object, ByVal e As System.EventArgs)
    'What Object raised Me
    If TypeOf (sender) Is Form Then
        Dim theNewForm As Form = CType(sender, Form)
        MsgBox(theNewForm.Name + " was loaded.")
    End If
End Sub
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900