My question is related to this question: Baseline snaplines in custom Winforms controls
我的问题与此问题有关:自定义Winforms控件中的基线捕捉线
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?
但是,就我而言,我创建了一个从TextBox派生而不是包含TextBox的新控件。我想有一个自定义的ControlDesigner,但我想修改TextBox设计师的行为,而不是自己编写一个完整的设计师。特别是,我希望能够在提供一些自定义动词的同时返回TextBox的SnapLines。有没有一个很好的方法来做到这一点?
EDIT: To clarify, this is for Windows Forms in .NET 2.0.
编辑:澄清一下,这是针对.NET 2.0中的Windows窗体。
2 个解决方案
#1
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.
最后,我决定使用的解决方案是在设计器中创建一个虚拟控件,将相关属性与实际控件同步,获取虚拟控件的设计器,然后从虚拟控件的设计器返回快照线。这是一个可怕的黑客,但它似乎是没有使用反射来“扩展”设计师的唯一方法。
#2
What about having your ControlDesigner derive from the one that TextBox is using? Did you try that and find a problem?
如何让ControlDesigner派生自TextBox正在使用的那个?你试过这个并找到问题吗?
#1
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.
最后,我决定使用的解决方案是在设计器中创建一个虚拟控件,将相关属性与实际控件同步,获取虚拟控件的设计器,然后从虚拟控件的设计器返回快照线。这是一个可怕的黑客,但它似乎是没有使用反射来“扩展”设计师的唯一方法。
#2
What about having your ControlDesigner derive from the one that TextBox is using? Did you try that and find a problem?
如何让ControlDesigner派生自TextBox正在使用的那个?你试过这个并找到问题吗?