views:

16

answers:

1

When I drag and drop a TextBox from the toolbox onto a WinForm, I can drag it around on the form as I like.

Now I create a new class and inherit it from TextBox. I add a new property called CaptionLabel. When set to a value, I dynamically create a Label control, set its value and finally add the label to the TextBox' parent controlcollection.

The result is a "LabeledTextBox".

However, when selecting the TextBox, I still only get the TextBox selected... the selection rectangle does not include the Label, created dynamically.

How do I extend the rectangle so that it also contains the Label and make the label "know" that it belongs to the TextBox?

Or is there a better way to create labeled controls?

A: 

if I understand correctly, you need to have one label and one TextBox were one element? if i right you need create new control, for that create new project type WindowsFormsControlLibrary?

Andriy Mytroshyn
Yes. I already have a Library Project. There are different ways of creating own controls. I could have put a Label and a TextBox into a usercontrol but then would have had to expose all of their properties manually. However, since I already have own (complex) usercontrols for an extended TextBox as well as a Label, I didn't want to have that overhead and instead simply inherit from my own TextBox and put the creation of a label (if needed) into a new Property.
Mephisztoe