I have an application in which I’d like to have objects inherit styles from the layer that they reside on.
For example, I’d like to have two layers for links. When a link resides on LinkLayerBlue, it is drawn with a blue pen, but if that link is moved to LinkLayerOrange, it automagically gets drawn with an orange pen. I’d like for this to happen without destroying the underlying object. I can think of several ways of doing this programatically (and without using layers), but I was hoping that layers could take care of this somehow. Any ideas?
Well, I suppose the most natural thing to do is to override Paint to do what you want depending on the layer that the object is in. (You probably should also deal with the object being in a different layer, or in no layer at all.)
Alternatively you could implement an override of OnLayerChanged, or a GoDocument.Changed event handler looking for one of the hints GoLayer.InsertedObject or ChangedObjectLayer, and then set the Pen as desired.
GoLayer is sealed, so you won’t be able to add any properties to it directly. You’ll need to keep that additional information elsewhere, indexed by layer.