views:

216

answers:

2

My question is related to this question: http://stackoverflow.com/questions/93541/baseline-snaplines-in-custom-winforms-controls

However, in my case, I have created a new control that derives from TextBox rather than containing a TextBox. I would like to have a custom ControlDesigner, but I would like to modify the behavior of the TextBox's designer rather than having to write a complete designer myself. In particular, I'd like to be able to return the TextBox's SnapLines while providing some custom verbs. Is there a good way to do this?

EDIT: To clarify, this is for Windows Forms in .NET 2.0.

A: 

What about having your ControlDesigner derive from the one that TextBox is using? Did you try that and find a problem?

John Saunders
How do I find the ControlDesigner that TextBox is using? I've looked around a bit but it was not immediately obvious.
Eric
Use .NET Reflector, or at worse, ILDASM.
John Saunders
.NET Reflector indicates its System.Windows.Forms.Design.TextBoxBaseDesigner, which is marked as an internal class so it's not an option.
Eric
@Eric: (Out of curiosity, was it you who downvoted, and was that the reason?) In any case, the next step would be to look at that designer in Reflector. It might derive from a public class, and might not be very complicated. A TextBox is not a very complicated control.
John Saunders
I downvoted because you are suggesting ideas for possible solutions, which you haven't tested and are not very helpful. If you would take the time to look at .NET Reflector, you would notice that each of the native controls has its own, internal designer class derived directly from ControlDesigner. These all include special functionality that seems a waste to try to reproduce in custom designers for controls derived from the native controls. Also, calling a TextBox "not a very complicated control" makes me suspect that you have never tried to create your own Baseline SnapLines.
Eric
@Eric: it's good to know what I did wrong. If you hadn't responded, I wouldn't have noticed that he's talking about WinForms, and I was thinking about ASP.NET. I'm more than willing to assume that the WinForms text box designer is much more complicated than the Web Forms text box designer. The web forms version might not even need its own designer. BTW, I have tested what I thought was being asked: i've derived designers for web controls in the past.
John Saunders
A: 

In the end, the solution I settled on was to create a dummy control in the designer, sync the relevant properties with the real control, get the designer for the dummy control, and then return the snaplines from the dummy control's designer. It's a terrible hack, but it seems to be the only way without using reflection to "extend" a designer.

Eric