How to put an extended WinForms Control on ToolBox

后端 未结 8 1957
自闭症患者
自闭症患者 2020-12-11 02:53

I plan to add functionalities to TextBox with the following:

   public class TextBoxExt : TextBox  
    {
        protected override void OnKeyPress(KeyPress         


        
8条回答
  •  旧巷少年郎
    2020-12-11 03:24

    I created an empty constructor for my custom implementation of UltraGridBagLayoutPanel. Although david.healed is right it isn't necessary, it is quite useful to put a breakpoint in to check that when the form initialises it is using your class to implement your custom control.

    It would have been a lot easier to edit the designer file, but I tried it and changed both the field type for the control and also changed the assignment of the field to a new instance of my custom control.

    private Infragistics.Win.Misc.UltraGridBagLayoutPanel ultraGridBagLayoutPanel1;
    this.ultraGridBagLayoutPanel1 = new Infragistics.Win.Misc.UltraGridBagLayoutPanel();
    

    to

    private Athia.Reports.ultraGridBagLayoutPanel1 ultraGridBagLayoutPanel1;
    this.ultraGridBagLayoutPanel1 = new Athia.Reports.ultraGridBagLayoutPanel1();
    

    Doing this destroys Visual Studio every time, and to fix it requires using a text editor to put it back again. Therefore unless anyone can describe what is wrong with my implementation of this approach, perhaps calling the class the same as the control name isn't a great idea, I think the only safe and reliable way to achieve this is as Calanus describes in steps 1 to 5 or as an small deviation from that as Rob Windsor rightly points out restarting VS will bring the control into the Toolbox automatically. Unfortunately for me I then have to change all of the child controls over from the original class to my customised class :-(.

提交回复
热议问题