inherit TextBox control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yoavo

    #1

    inherit TextBox control

    Hi,
    I have a dialog with 2 TextBox controls.
    I want to add some functionality to one of the them.
    I created a class MyTextBox which inherits from TextBox.
    How can I connect one of the TextBox controls to my new class ?

    Yoav.


  • Alberto Poblacion

    #2
    Re: inherit TextBox control

    "Yoavo" <yoav@cimatron. co.ilwrote in message
    news:eiU4tQQCIH A.4712@TK2MSFTN GP04.phx.gbl...
    I have a dialog with 2 TextBox controls.
    I want to add some functionality to one of the them.
    I created a class MyTextBox which inherits from TextBox.
    How can I connect one of the TextBox controls to my new class ?
    You don't exactly "connect" the textbox with the new class. Instead, the
    textbox has to be an instance of the new class. Search your source code for
    the place where the textbox is declared and initialized. If you are using
    Visual Studio 2002/2003, this is in the .cs file for your Form in the block
    labelled "designer generated code". If You are using VS 2005, you have to
    click on the icon "show all files" in solution explorer, and then open the
    file with the extension .designer.cs. You will find declarations similar to
    this ones:

    TextBox texbox1;
    ...
    textbox1 = new TextBox();

    In those two lines, replace TexBox with MyTextBox, and you are done.

    Another way to do it is to compile your new class into a dll, and then
    add it to the toolbx in the windows forms designer (right-click on the
    toolbox). Once you do that, the MyTextBox will appear in the toolbox, and
    you can drag it from there into your form just like the standard textbox. If
    you are using version 2005, you don't need to do any of this, since the
    controls defined inside your project will appear automatically at the top of
    the toolbox, under "myproject components".


    Comment

    • Yoavo

      #3
      Re: inherit TextBox control

      I am using VS 2005 and my application is a WPF program.
      The wizard created a file "Window1.g. cs" and in it there is the window
      class:
      public partial class Window1 : System.Windows. Window,
      System.Windows. Markup.ICompone ntConnector {
      ....
      internal System.Windows. Controls.TextBo x YoavTextBox;
      }


      with the method:
      void System.Windows. Markup.ICompone ntConnector.Con nect(int connectionId,
      object target) {
      ....
      this.YoavTextBo x = ((System.Window s.Controls.Text Box)(target));
      }

      when I tried to replace "System.Windows .Controls.TextB ox" with "MyTextBox" ,
      I got compilation errors.



      "Alberto Poblacion" <earthling-quitaestoparaco ntestar@poblaci on.orgwrote
      in message news:%23pK2qZQC IHA.3884@TK2MSF TNGP05.phx.gbl. ..
      "Yoavo" <yoav@cimatron. co.ilwrote in message
      news:eiU4tQQCIH A.4712@TK2MSFTN GP04.phx.gbl...
      >I have a dialog with 2 TextBox controls.
      >I want to add some functionality to one of the them.
      >I created a class MyTextBox which inherits from TextBox.
      >How can I connect one of the TextBox controls to my new class ?
      >
      You don't exactly "connect" the textbox with the new class. Instead, the
      textbox has to be an instance of the new class. Search your source code
      for the place where the textbox is declared and initialized. If you are
      using Visual Studio 2002/2003, this is in the .cs file for your Form in
      the block labelled "designer generated code". If You are using VS 2005,
      you have to click on the icon "show all files" in solution explorer, and
      then open the file with the extension .designer.cs. You will find
      declarations similar to this ones:
      >
      TextBox texbox1;
      ...
      textbox1 = new TextBox();
      >
      In those two lines, replace TexBox with MyTextBox, and you are done.
      >
      Another way to do it is to compile your new class into a dll, and then
      add it to the toolbx in the windows forms designer (right-click on the
      toolbox). Once you do that, the MyTextBox will appear in the toolbox, and
      you can drag it from there into your form just like the standard textbox.
      If you are using version 2005, you don't need to do any of this, since the
      controls defined inside your project will appear automatically at the top
      of the toolbox, under "myproject components".
      >
      >

      Comment

      • Alberto Poblacion

        #4
        Re: inherit TextBox control

        "Yoavo" <yoav@cimatron. co.ilwrote in message
        news:uvsbz2WCIH A.4496@TK2MSFTN GP06.phx.gbl...
        >I am using VS 2005 and my application is a WPF program.
        Ah, sorry. Since you didn't specify, I thought you were doing a plain
        old WinForms application. I have played a little bit with WPF, but I have
        not gone far enough to know how to subclass controls on this platform.
        Someone more knowledgeable than me will have to provide the answer.



        Comment

        Working...