Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27351

Objects should only be interfered with by public properties or event, however...

$
0
0
I'm trying to stick to the above rule, but I'm running in a situation where I do need an advice.
It is the same code I posted before, however another question it.

I need to AddHandles during Runtime. Actually I do that from a module like:
vb Code:
  1. For Each g As usrGram In MainForm.GramList
  2.    AddHandler b.PingerPing, AddressOf g.Ping_zeichnen 'b as an ObjectType with a Event called PingerPing
  3. Next
MainForm is the Starting Form which holds some UserControls (usrGram)
b are of Type ClassSomething, (as of now) neither a part of MainForm nor the UserControl.

I need each UserControl to react the Event PingerPing of each b, therefore I use the above AddHandler in the code which initially creates b. This code is in a module.
Because it is in a module the Sub "Ping_zeichnen" of the UserControl has to be Public, and that's the point.
The only way around this would be to make two events, one from b, on which a sub in the module is run, which raises an event on which the UserControl is already reacting.
The only other way I see to avoid the Public Sub is to use AddHandler in situation when there is already the Handler added/ RemoveHandler when the handler is already removed. Is there something that tells you if a specific handler is set or removed?

Viewing all articles
Browse latest Browse all 27351

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>