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] "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 =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> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Try</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2> Dim mf as new=20
Form1</FONT></DIV>
<DIV><FONT=20
size=3D2> &nbs=
p;mf.ShowDialog()</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Catch GeneralException as Exception</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>'</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>End Try</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><BR>-- <BR>OHM ( Terry Burns ) * Use the following to =
email me=20
*</DIV>
<DIV> </DIV>
<DIV> Dim ch() As Char =3D=20
"ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()<BR> For i As =
Int32 =3D 0=20
To ch.Length - 1<BR> ch(i) =3D=20
Convert.ToChar(Convert.ToInt16(ch(i)) -=20
1)<BR> Next<BR> Process.Start("mailto:" & New=20
String(ch))<BR>--</DIV>
<DIV> </DIV>
<DIV> </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" <<A=20
=
href=3D"mailto:ganiguy@netvision.net.il">ganiguy@netvision.net.il</A>>=
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> </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> </DIV>
<DIV><FONT face=3DTerminal size=3D2>Private ctl_Module As=20
Windows.Forms.UserControl =20
'Embedded user control object</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DTerminal size=3D2> Dim Idx As=20
Integer</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2> Dim eh As=20
System.Delegate</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT> </DIV>
<DIV><FONT face=3DTerminal size=3D2> eh =3D New=20
EventHandler(AddressOf myGeneralEventHandler)</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2> Dim events_info =
As=20
System.Reflection.EventInfo() =3D =
ctl_Module.GetType.GetEvents()</FONT></DIV>
<DIV><FONT face=3DTerminal size=3D2></FONT> </DIV>
<DIV><FONT face=3DTerminal size=3D2> For Idx =3D 0 =