Re: General Event Handler
From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 11/05/04
- Next message: One Handed Man \( OHM - Terry Burns \): "Re: Shift the webform files into a new folder within a particular project"
- Previous message: Kejpa: "Re: Collectionbase with key"
- In reply to: Guy Gani: "General Event Handler"
- Next in thread: Guy Gani: "Re: General Event Handler"
- Reply: Guy Gani: "Re: General Event Handler"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 5 Nov 2004 08:55:31 -0000
You could start your application from a Sub Main, and have a Try / Catch Block around the form
Try
Dim mf as new Form1
mf.ShowDialog()
Catch GeneralException as Exception
'
End Try
--
OHM ( Terry Burns ) * Use the following to email me *
Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Guy Gani" <ganiguy@netvision.net.il> wrote in message news:%234wMC5wwEHA.3528@tk2msftngp13.phx.gbl...
Hello,
I have a small application with one form and a user control on it. The user control is loaded during runtime and can be changed when the user selects the appropriate one from a tree, something like microsoft .msc files.
I would like to have one function on the form that handles all the user events that raised from the various user controls. The problem is that that user controls are different and raised different events and I couldn't figure out how to do that. (it is possible in VB6 by declaring the user control with VBControlExtender and handle all events using ObjectEvent procedure on the form).
I used the following code whenever creating the usercontrol at runtime on the form:
Private ctl_Module As Windows.Forms.UserControl 'Embedded user control object
Private Sub ShowControl(ByRef pCtrl As Windows.Forms.UserControl)
Dim Idx As Integer
Dim eh As System.Delegate
eh = New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() = ctl_Module.GetType.GetEvents()
For Idx = 0 To events_info.Length - 1
If events_info(Idx).Name = "LogStatus" Then 'Test to exclude user control events
events_info(Idx).AddEventHandler(pCtrl, eh) '<-- This is where the error occured
End If
Next
End Sub
This piece of code compiles fine, however when I run it I got the following error message:
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Object type cannot be converted to target type.
Anyone knows why ?
Thanks,
Guy
- Next message: One Handed Man \( OHM - Terry Burns \): "Re: Shift the webform files into a new folder within a particular project"
- Previous message: Kejpa: "Re: Collectionbase with key"
- In reply to: Guy Gani: "General Event Handler"
- Next in thread: Guy Gani: "Re: General Event Handler"
- Reply: Guy Gani: "Re: General Event Handler"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|