Home All Groups Group Topic Archive Search About

User Control Subclassing

Author
13 May 2005 3:10 PM
Joel Whitehouse
Hello All,

I am writing a usercontrol to work with a multithreaded .dll, and I am
using subclassing to intercept messages back from the .dll.  Subclassing
requires that I pass a window-handle to the .dll so that the .dll knows
where to send messages back to, so I added a form to the UserControl
project to handle messages.

So, when certain messages come through to the form, I want to raise an
event in the UserControl object.  The problem is that when I call the
"RaiseEvent" keyword in the form object, I get a message saying that the
event that I am trying to call does not exist.  In reality, the Event
that I'm trying to raise just doesn't exist in the form object - but is
does exist in the UserControl object.  How can I make the form throw
events in the UserControl scope?

Thanks for your help!

-Joel Whitehouse

Author
13 May 2005 3:15 PM
Bob Butler
"Joel Whitehouse" <joelwhiteho***@gmail.com> wrote in message
news:ur3he.78091$WI3.22015@attbi_s71
> How can I make the form
> throw events in the UserControl scope?

You need to
a) define the event in the form
b) have the usercontrol declare the form reference "WithEvents"
c) raise the event in the form
d) respond to the event in the usercontrol and raise the event again from
there

-or-

have some other callback mechanism from the form to the usercontrol to tell
it to raise the event

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
13 May 2005 3:40 PM
Joel Whitehouse
Bob Butler wrote:>
> You need to
> a) define the event in the form
> b) have the usercontrol declare the form reference "WithEvents"
> c) raise the event in the form
> d) respond to the event in the usercontrol and raise the event again from
> there

Thanks Bob.  I'm lookink into "withevents" right now.


> have some other callback mechanism from the form to the usercontrol to tell
> it to raise the event
I tried the callback, but it had to be public, and it exposed too much
of the UserControl's inner workings to the user...
Author
13 May 2005 3:51 PM
Bob Butler
"Joel Whitehouse" <joelwhiteho***@gmail.com> wrote in message
news:LT3he.78116$WI3.65850@attbi_s71
>> have some other callback mechanism from the form to the usercontrol
>> to tell it to raise the event
> I tried the callback, but it had to be public, and it exposed too much
> of the UserControl's inner workings to the user...

Did you try 'Friend' ? 

BTW, I agree with Ken that if you can get rid of the form that'd be best

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
13 May 2005 3:21 PM
Ken Halter
"Joel Whitehouse" <joelwhiteho***@gmail.com> wrote in message
news:ur3he.78091$WI3.22015@attbi_s71...
> Hello All,
>
> I am writing a usercontrol to work with a multithreaded .dll, and I am
> using subclassing to intercept messages back from the .dll.  Subclassing
> requires that I pass a window-handle to the .dll so that the .dll knows
> where to send messages back to, so I added a form to the UserControl
> project to handle messages.

In the usercontrol, you can add a public sub that fires an event and call
that from the form.
'=======
Public Event FireONE(SomeText As String)

Public Sub RaiseTheEvent(SomeInfo As String)
   RaiseEvent FireONE(SomeInfo)
End Sub
'=======

Why add a form though? Why not pass the handle to the UserControl?

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
13 May 2005 3:38 PM
Joel Whitehouse
>
> Why add a form though? Why not pass the handle to the UserControl?
>

I wasn't aware that a UserControl hWnd would function correctly.  I'll
try it out.
Author
13 May 2005 10:13 PM
J French
On Fri, 13 May 2005 15:38:13 GMT, Joel Whitehouse
<joelwhiteho***@gmail.com> wrote:

>>
>> Why add a form though? Why not pass the handle to the UserControl?
>>

>I wasn't aware that a UserControl hWnd would function correctly.  I'll
>try it out.

It will

And then you can get rid of that redundant Form

AddThis Social Bookmark Button