all groups > vb.net upgrade > november 2004 >
You're in the

vb.net upgrade

group:

General Event Handler



Re: General Event Handler One Handed Man \( OHM - Terry Burns \)
11/5/2004 8:55:31 AM
vb.net upgrade: This is a multi-part message in MIME format.

------=_NextPart_000_0224_01C4C315.344C4640
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

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


--=20
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char =3D "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 =3D 0 To ch.Length - 1
ch(i) =3D Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


[quoted text, click to view]
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 =3D New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()

For Idx =3D 0 To events_info.Length - 1
If events_info(Idx).Name =3D "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



------=_NextPart_000_0224_01C4C315.344C4640
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1255">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>You could start your application from a Sub Main, =
and have a=20
Try / Catch Block around the form</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Try</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim mf as new=20
Form1</FONT></DIV>
<DIV><FONT=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;mf.ShowDialog()</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Catch GeneralException as Exception</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>'</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>End Try</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><BR>-- <BR>OHM ( Terry Burns )&nbsp;&nbsp; * Use the following to =
email me=20
*</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Dim ch() As Char =3D=20
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()<BR>&nbsp;For i As =
Int32 =3D 0=20
To ch.Length - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp; ch(i) =3D=20
Convert.ToChar(Convert.ToInt16(ch(i)) -=20
1)<BR>&nbsp;Next<BR>&nbsp;Process.Start("mailto:" &amp; New=20
String(ch))<BR>--</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Guy Gani" &lt;<A=20
=
href=3D"mailto:ganiguy@netvision.net.il">ganiguy@netvision.net.il</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:%234wMC5wwEHA.3528@tk2msftngp13.phx.gbl">news:%234wMC5wwEHA.=
3528@tk2msftngp13.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a small application with one =
form and a=20
user control on it. The user control is loaded during runtime and can =
be=20
changed when the user selects the appropriate one from a tree, =
something like=20
microsoft .msc files.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I would like to have one function on =
the form=20
that handles all the user events that raised from the various user =
controls.=20
The problem is that that user controls are different and raised =
different=20
events and I couldn't figure out how to do that. (it is possible in =
VB6 by=20
declaring the user control with VBControlExtender and handle all =
events using=20
ObjectEvent procedure on the form).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I used the following code whenever =
creating the=20
usercontrol at runtime on the form:</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private ctl_Module As=20
Windows.Forms.UserControl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; 'Embedded user control object</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private Sub ShowControl(ByRef =
pCtrl As=20
Windows.Forms.UserControl)</FONT><FONT face=3DTerminal =
size=3D2></FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim Idx As=20
Integer</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim eh As=20
System.Delegate</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; eh =3D New=20
EventHandler(AddressOf myGeneralEventHandler)</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim events_info =
As=20
System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; For Idx =3D 0 =
Re: General Event Handler One Handed Man \( OHM - Terry Burns \)
11/5/2004 9:21:27 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0283_01C4C318.D4251D10
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

This on its own does not give me enough information. As you say this =
compiles ok, but I dont know how you are calling the show control and =
what you have on the form.

--=20
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char =3D "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 =3D 0 To ch.Length - 1
ch(i) =3D Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


[quoted text, click to view]
This is a nice workaround that I haven't tought about, however I would =
like to handle on the form the user control events raised by RaiseEvent =
and deal with exceptions in the regular exception handler.
Please take a look at my code and see why it breaks, if this piece of =
code is fixed, it should work fine.

Thanks

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in =
message news:%23$oMsUxwEHA.384@tk2msftngp13.phx.gbl...
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


--=20
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char =3D =
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 =3D 0 To ch.Length - 1
ch(i) =3D Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


[quoted text, click to view]
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 =3D New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()

For Idx =3D 0 To events_info.Length - 1
If events_info(Idx).Name =3D "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



------=_NextPart_000_0283_01C4C318.D4251D10
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1255">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>This on its own does not give me enough information. =
As you=20
say this compiles ok, but I dont know how you are calling the show =
control and=20
what you have on the form.</FONT></DIV>
<DIV><BR>-- <BR>OHM ( Terry Burns )&nbsp;&nbsp; * Use the following to =
email me=20
*</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Dim ch() As Char =3D=20
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()<BR>&nbsp;For i As =
Int32 =3D 0=20
To ch.Length - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp; ch(i) =3D=20
Convert.ToChar(Convert.ToInt16(ch(i)) -=20
1)<BR>&nbsp;Next<BR>&nbsp;Process.Start("mailto:" &amp; New=20
String(ch))<BR>--</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Guy Gani" &lt;<A=20
=
href=3D"mailto:ganiguy@netvision.net.il">ganiguy@netvision.net.il</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:%238QqjZxwEHA.3612@tk2msftngp13.phx.gbl">news:%238QqjZxwEHA.=
3612@tk2msftngp13.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>This is a nice workaround that I =
haven't tought=20
about, however I would like to handle on the form the user control =
events=20
raised by RaiseEvent and deal with exceptions in the regular exception =

handler.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Please take a look at my code and see =
why it=20
breaks, if this piece of code is fixed, it should work =
fine.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</FONT>"One Handed Man ( OHM - =
Terry Burns=20
[quoted text, click to view]
href=3D"news:%23$oMsUxwEHA.384@tk2msftngp13.phx.gbl">news:%23$oMsUxwEHA.3=
84@tk2msftngp13.phx.gbl</A>...</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV><FONT size=3D2>You could start your application from a Sub =
Main, and have=20
a Try / Catch Block around the form</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Try</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim mf as =
new=20
Form1</FONT></DIV>
<DIV><FONT=20
=
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;mf.ShowDialog()</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Catch GeneralException as Exception</FONT></DIV>
General Event Handler Guy Gani
11/5/2004 10:05:52 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C4C31F.0837E5A0
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

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 =3D New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()

For Idx =3D 0 To events_info.Length - 1
If events_info(Idx).Name =3D "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



------=_NextPart_000_0006_01C4C31F.0837E5A0
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1255">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a small application with one =
form and a user=20
control on it. The user control is loaded during runtime and can be =
changed when=20
the user selects the appropriate one from a tree, something like =
microsoft .msc=20
files.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I would like to have one function on =
the form that=20
handles all the user events that raised from the various user controls. =
The=20
problem is that that user controls are different and raised different =
events and=20
I couldn't figure out how to do that. (it is possible in VB6 by =
declaring the=20
user control with VBControlExtender and handle all events using =
ObjectEvent=20
procedure on the form).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I used the following code whenever =
creating the=20
usercontrol at runtime on the form:</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private ctl_Module As=20
Windows.Forms.UserControl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; 'Embedded user control object</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private Sub ShowControl(ByRef pCtrl =
As=20
Windows.Forms.UserControl)</FONT><FONT face=3DTerminal =
size=3D2></FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim Idx As=20
Integer</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim eh As=20
System.Delegate</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; eh =3D New=20
EventHandler(AddressOf myGeneralEventHandler)</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim events_info =
As=20
System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; For Idx =3D 0 To=20
events_info.Length - 1</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; If=20
events_info(Idx).Name =3D "LogStatus"=20
Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Test to exclude =
user=20
control events</FONT></DIV>
<DIV><FONT face=3DTerminal color=3D#ff0000 size=3D2>&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
events_info(Idx).AddEventHandler(pCtrl,=20
eh)&nbsp;&nbsp;&nbsp; '&lt;-- This is where the error =
occured</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; End=20
If</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Next</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>End Sub</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This piece of code compiles fine, =
however when I=20
run it I got the following error message:</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2>An unhandled exception =
of type=20
'System.ArgumentException' occurred in mscorlib.dll</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2>Additional information: =
Object type=20
cannot be converted to target type.</FONT></DIV>
<DIV><FONT face=3DArial color=3D#ff0000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anyone knows why ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Guy</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV>
<DIV><BR></DIV></FONT></BODY></HTML>

------=_NextPart_000_0006_01C4C31F.0837E5A0--
Re: General Event Handler Guy Gani
11/5/2004 11:03:56 AM
This is a multi-part message in MIME format.

------=_NextPart_000_0016_01C4C327.288A9C50
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

This is a nice workaround that I haven't tought about, however I would =
like to handle on the form the user control events raised by RaiseEvent =
and deal with exceptions in the regular exception handler.
Please take a look at my code and see why it breaks, if this piece of =
code is fixed, it should work fine.

Thanks

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in =
message news:%23$oMsUxwEHA.384@tk2msftngp13.phx.gbl...
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


--=20
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char =3D =
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 =3D 0 To ch.Length - 1
ch(i) =3D Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


[quoted text, click to view]
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 =3D New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()

For Idx =3D 0 To events_info.Length - 1
If events_info(Idx).Name =3D "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



------=_NextPart_000_0016_01C4C327.288A9C50
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1255">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is a nice workaround that I =
haven't tought=20
about, however I would like to handle on the form the user control =
events raised=20
by RaiseEvent and deal with exceptions in the regular exception=20
handler.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Please take a look at my code and see =
why it=20
breaks, if this piece of code is fixed, it should work =
fine.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</FONT>"One Handed Man ( OHM - =
Terry Burns )"=20
[quoted text, click to view]
84@tk2msftngp13.phx.gbl</A>...</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV><FONT size=3D2>You could start your application from a Sub Main, =
and have a=20
Try / Catch Block around the form</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Try</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim mf as new =

Form1</FONT></DIV>
<DIV><FONT=20
=
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;mf.ShowDialog()</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Catch GeneralException as Exception</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>'</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>End Try</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><BR>-- <BR>OHM ( Terry Burns )&nbsp;&nbsp; * Use the following to =
email=20
me *</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;Dim ch() As Char =3D=20
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()<BR>&nbsp;For i As =
Int32 =3D 0=20
To ch.Length - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp; ch(i) =3D=20
Convert.ToChar(Convert.ToInt16(ch(i)) -=20
1)<BR>&nbsp;Next<BR>&nbsp;Process.Start("mailto:" &amp; New=20
String(ch))<BR>--</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Guy Gani" &lt;<A=20
=
href=3D"mailto:ganiguy@netvision.net.il">ganiguy@netvision.net.il</A>&gt;=
=20
[quoted text, click to view]
href=3D"news:%234wMC5wwEHA.3528@tk2msftngp13.phx.gbl">news:%234wMC5wwEHA.=
3528@tk2msftngp13.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a small application with one =
form and a=20
user control on it. The user control is loaded during runtime and =
can be=20
changed when the user selects the appropriate one from a tree, =
something=20
like microsoft .msc files.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I would like to have one function =
on the form=20
that handles all the user events that raised from the various user =
controls.=20
The problem is that that user controls are different and raised =
different=20
Re: General Event Handler Paul
11/5/2004 1:14:08 PM
This is a multi-part message in MIME format.

------=_NextPart_000_00A1_01C4C339.582A5CE0
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

Perhaps I'm wrong but this sounds like a solution I found in MS =
IssueVision Smart Client sample app (nice!). This uses a command object =
to sink the events to a common handler. See Command.vb class in =
download. =
http://www.windowsforms.net/Applications/application.aspx?PageID=3D40&tab=
index=3D9

Paul
[quoted text, click to view]
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 =3D New EventHandler(AddressOf myGeneralEventHandler)
Dim events_info As System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()

For Idx =3D 0 To events_info.Length - 1
If events_info(Idx).Name =3D "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



------=_NextPart_000_00A1_01C4C339.582A5CE0
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1255">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Perhaps I'm wrong but this sounds like a solution I =
found in=20
MS IssueVision Smart Client sample app (nice!). This uses a command =
object to=20
sink the events to a common handler. See Command.vb class in download. =
<A=20
href=3D"http://www.windowsforms.net/Applications/application.aspx?PageID=3D=
40&amp;tabindex=3D9">http://www.windowsforms.net/Applications/application=
..aspx?PageID=3D40&amp;tabindex=3D9</A></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Paul</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Guy Gani" &lt;<A=20
=
href=3D"mailto:ganiguy@netvision.net.il">ganiguy@netvision.net.il</A>&gt;=
wrote=20
in message <A=20
=
href=3D"news:%234wMC5wwEHA.3528@tk2msftngp13.phx.gbl">news:%234wMC5wwEHA.=
3528@tk2msftngp13.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have a small application with one =
form and a=20
user control on it. The user control is loaded during runtime and can =
be=20
changed when the user selects the appropriate one from a tree, =
something like=20
microsoft .msc files.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I would like to have one function on =
the form=20
that handles all the user events that raised from the various user =
controls.=20
The problem is that that user controls are different and raised =
different=20
events and I couldn't figure out how to do that. (it is possible in =
VB6 by=20
declaring the user control with VBControlExtender and handle all =
events using=20
ObjectEvent procedure on the form).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I used the following code whenever =
creating the=20
usercontrol at runtime on the form:</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private ctl_Module As=20
Windows.Forms.UserControl&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; 'Embedded user control object</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>Private Sub ShowControl(ByRef =
pCtrl As=20
Windows.Forms.UserControl)</FONT><FONT face=3DTerminal =
size=3D2></FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim Idx As=20
Integer</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim eh As=20
System.Delegate</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; eh =3D New=20
EventHandler(AddressOf myGeneralEventHandler)</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; Dim events_info =
As=20
System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; For Idx =3D 0 =
To=20
events_info.Length - 1</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; If=20
events_info(Idx).Name =3D "LogStatus"=20
Then&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Test to exclude =
user=20
control events</FONT></DIV>
<DIV><FONT face=3DTerminal color=3D#ff0000 size=3D2>&nbsp;&nbsp;&nbsp; =

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
events_info(Idx).AddEventHandler(pCtrl,=20
eh)&nbsp;&nbsp;&nbsp; '&lt;-- This is where the error =
occured</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; End=20
If</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2>&nbsp;&nbsp;&nbsp; =
Next</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DTerminal size=3D2>End Sub</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This piece of code compiles fine, =
however when I=20
AddThis Social Bookmark Button