Re: General Event Handler

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: One Handed Man \( OHM - Terry Burns \) ("One)
Date: 11/05/04


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


Relevant Pages

  • Re: JiT Debugger w/ StackOverflowException kept appearing
    ... has to do with using domain account to access local web application. ... Sub Foo() ... It might also be helpful to post the full stack trace of the exception. ... Dim ldsPage As New DataSet ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: JiT Debugger w/ StackOverflowException kept appearing
    ... Sub Foo() ... It might also be helpful to post the full stack trace of the exception. ... Dim ldsPage As New DataSet ... Dim lobjDBHelper As New DBHelper ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Timer Problem
    ... Public Sub New ... ' Dieser Aufruf ist für den Komponenten-Designer erforderlich. ... Dim iSCManagerLockHandle As Integer ... If not throw an exception. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Windows App... processing completes before form is painted on
    ... Public Sub New ... Dim t As System.Threading.Thread ... Dim sArchiveFilePath As String ... Catch ex As Exception ...
    (microsoft.public.dotnet.general)
  • Re: General Event Handler
    ... The user control is loaded during runtime and can be changed when the user selects the appropriate one from a tree, ... Private Sub ShowControlDim Idx As Integer ... 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. ...
    (microsoft.public.dotnet.framework)