I want to make a control which inherits from TextBox and which has a label inside which "sticks" to the right side of the text box and which text is not user-editable but rather is set by a property. How can this be done? I realize there may be many reasons why this UX is a bad idea, but I have to do it this way.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
I will suggest you to create a
UserControl
withTextBox
and aLabel
docked right. That should be pain less and bug free.As you said you already use
TextBox
to avoid much refactoring you can add all the properties you used in TextBox as "Proxy properties". Something like this:This can help you to avoid much refactoring.
I would actually create a composit control, or simply a UserControl, and put a label and textbox next to each other. Then you can remove the borders around the textbox and surround them with a borderbox to mimic the normal textbox design.
Finally I would make sure that the user controls properties, like
Text
is mapped to the Textbox, so it is easy to use the control as a drop-replacement.Adapting from Hans Passant's Button inside a winforms textbox answer:
Result: