Let me provide you with an example that may be useful to you.....
See attachment
Note that the provided code is untested. You'll have to implement your own way of handling the position, anchoring, attributes and control-specific stuff, but I think you'll be OK with this