Textbox question

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

    #1

    Textbox question

    Hi all,

    In my form have more then 10 textbox. I would like to make all textbox
    when lostfocus backcolor is white, when gotfocus backcolor is yellow. But I
    don't want to write same code in the form. How to solve this problem. Is it
    can make a textbox class to control or some other method?

    Thanks


  • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

    #2
    RE: Textbox question

    Localbar,

    Use one event handler for all the textboxs's Gotfocus and Lostfocus events.
    For example:

    Private Sub Textbox_GotFocu s(ByVal sender As Object, _
    ByVal e As System.EventArg s) Handles txtName.GotFocu s, _
    txtTest1.GotFoc us, _
    txtTest2.GotFoc us, _
    txtAverage.GotF ocus

    Kerry Moorman


    "Localbar" wrote:
    Hi all,
    >
    In my form have more then 10 textbox. I would like to make all textbox
    when lostfocus backcolor is white, when gotfocus backcolor is yellow. But I
    don't want to write same code in the form. How to solve this problem. Is it
    can make a textbox class to control or some other method?
    >
    Thanks
    >
    >
    >

    Comment

    • RobinS

      #3
      Re: Textbox question

      Create a base form that has no UI, all it does it loop through the controls
      on the form and set the event handlers. I would recommend using Enter and
      Leave instead of the Focus events, by the way.

      Then have all of your forms inherit from the base form, and it will behave
      the same all over the place.

      Robin S.
      --------------------------------
      "Localbar" <localbar.hk@gm ail.comwrote in message
      news:u2uoZO9fHH A.4692@TK2MSFTN GP03.phx.gbl...
      Hi all,
      >
      In my form have more then 10 textbox. I would like to make all
      textbox
      when lostfocus backcolor is white, when gotfocus backcolor is yellow. But
      I
      don't want to write same code in the form. How to solve this problem. Is
      it
      can make a textbox class to control or some other method?
      >
      Thanks
      >
      >

      Comment

      • Localbar

        #4
        Re: Textbox question

        Hi Robin,

        Can tell me more detail, After I create the form is no UI. and then how
        to do? ..No need to add textbox in baseform ?

        Thanks

        "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
        news:dKmdndWW5M XqlL7bnZ2dnUVZ_ rSjnZ2d@comcast .com ¤¤¼¶¼g...
        Create a base form that has no UI, all it does it loop through the
        controls
        on the form and set the event handlers. I would recommend using Enter and
        Leave instead of the Focus events, by the way.
        >
        Then have all of your forms inherit from the base form, and it will behave
        the same all over the place.
        >
        Robin S.
        --------------------------------
        "Localbar" <localbar.hk@gm ail.comwrote in message
        news:u2uoZO9fHH A.4692@TK2MSFTN GP03.phx.gbl...
        Hi all,

        In my form have more then 10 textbox. I would like to make all
        textbox
        when lostfocus backcolor is white, when gotfocus backcolor is yellow.
        But
        I
        don't want to write same code in the form. How to solve this problem. Is
        it
        can make a textbox class to control or some other method?

        Thanks
        >
        >

        Comment

        • Localbar

          #5
          Re: Textbox question

          Thanks Kerry..Let me try now

          "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.com¦b¶l¥ó
          news:C0626158-3151-401B-A5F2-94BAAAEF3D50@mi crosoft.com ¤¤¼¶¼g...
          Localbar,
          >
          Use one event handler for all the textboxs's Gotfocus and Lostfocus
          events.
          For example:
          >
          Private Sub Textbox_GotFocu s(ByVal sender As Object, _
          ByVal e As System.EventArg s) Handles txtName.GotFocu s, _
          txtTest1.GotFoc us, _
          txtTest2.GotFoc us, _
          txtAverage.GotF ocus
          >
          Kerry Moorman
          >
          >
          "Localbar" wrote:
          >
          Hi all,

          In my form have more then 10 textbox. I would like to make all
          textbox
          when lostfocus backcolor is white, when gotfocus backcolor is yellow.
          But I
          don't want to write same code in the form. How to solve this problem. Is
          it
          can make a textbox class to control or some other method?

          Thanks


          Comment

          • RobinS

            #6
            Re: Textbox question

            Create a form and call it something like BaseForm. Don't put any controls
            on it.

            Put this in the code behind the form:

            Private Sub AddEventHandler s(ByVal ctrlContainer As Control)
            For Each ctrl As Control In ctrlContainer.C ontrols
            If TypeOf ctrl Is TextBox _
            OrElse TypeOf ctrl Is ComboBox Then
            AddHandler ctrl.Enter, AddressOf ProcessEnter
            AddHandler ctrl.Leave, AddressOf ProcessLeave
            End If
            'If control has children, call this function recursively
            If ctrl.HasChildre n Then
            AddEventHandler s(ctrl)
            End If
            Next
            End Sub
            Private Sub ProcessEnter(By Val sender as Object, ByVal e as
            System.EventArg s)
            DirectCast(send er, Control).BackCo lor = Color.Lavender
            End Sub
            Private Sub ProcessLeave(By Val sender as Object, ByVal e as
            System.EventArg s)
            DirectCast(send er, Control).BackCo lor =
            Color.FromKnown Color(KnownColo r.Window)
            End Sub

            Add the BaseForm_Load event and put this in there:

            AddEventHandler s(me)

            Then create your new form, and either change it to inherit from BaseForm
            (this is probably in the designer-generated code), or use the Inheritance
            Picker to create your new form (which does the same thing).

            Put your textboxes on your new form, and run it, and voila! You get colors
            when you enter a textbox, and back to the original color when they leave.

            If you have every form inherit from the BaseForm, it will work the same on
            every form with no further effort on your part.

            Robin S.
            -----------------------------
            "Localbar" <localbar.hk@gm ail.comwrote in message
            news:u4nkVp%23f HHA.5056@TK2MSF TNGP02.phx.gbl. ..
            Hi Robin,
            >
            Can tell me more detail, After I create the form is no UI. and then
            how
            to do? ..No need to add textbox in baseform ?
            >
            Thanks
            >
            "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
            news:dKmdndWW5M XqlL7bnZ2dnUVZ_ rSjnZ2d@comcast .com ¤¤¼¶¼g...
            >Create a base form that has no UI, all it does it loop through the
            controls
            >on the form and set the event handlers. I would recommend using Enter
            >and
            >Leave instead of the Focus events, by the way.
            >>
            >Then have all of your forms inherit from the base form, and it will
            >behave
            >the same all over the place.
            >>
            >Robin S.
            >--------------------------------
            >"Localbar" <localbar.hk@gm ail.comwrote in message
            >news:u2uoZO9fH HA.4692@TK2MSFT NGP03.phx.gbl.. .
            Hi all,
            >
            In my form have more then 10 textbox. I would like to make all
            textbox
            when lostfocus backcolor is white, when gotfocus backcolor is yellow.
            But
            I
            don't want to write same code in the form. How to solve this problem.
            Is
            it
            can make a textbox class to control or some other method?
            >
            Thanks
            >
            >
            >>
            >>
            >
            >

            Comment

            • Localbar

              #7
              Re: Textbox question

              Thanks RobinS..It done.

              "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
              news:06qdnXR1he Rru77bnZ2dnUVZ_ gGdnZ2d@comcast .com ¤¤¼¶¼g...
              Create a form and call it something like BaseForm. Don't put any controls
              on it.
              >
              Put this in the code behind the form:
              >
              Private Sub AddEventHandler s(ByVal ctrlContainer As Control)
              For Each ctrl As Control In ctrlContainer.C ontrols
              If TypeOf ctrl Is TextBox _
              OrElse TypeOf ctrl Is ComboBox Then
              AddHandler ctrl.Enter, AddressOf ProcessEnter
              AddHandler ctrl.Leave, AddressOf ProcessLeave
              End If
              'If control has children, call this function recursively
              If ctrl.HasChildre n Then
              AddEventHandler s(ctrl)
              End If
              Next
              End Sub
              Private Sub ProcessEnter(By Val sender as Object, ByVal e as
              System.EventArg s)
              DirectCast(send er, Control).BackCo lor = Color.Lavender
              End Sub
              Private Sub ProcessLeave(By Val sender as Object, ByVal e as
              System.EventArg s)
              DirectCast(send er, Control).BackCo lor =
              Color.FromKnown Color(KnownColo r.Window)
              End Sub
              >
              Add the BaseForm_Load event and put this in there:
              >
              AddEventHandler s(me)
              >
              Then create your new form, and either change it to inherit from BaseForm
              (this is probably in the designer-generated code), or use the Inheritance
              Picker to create your new form (which does the same thing).
              >
              Put your textboxes on your new form, and run it, and voila! You get colors
              when you enter a textbox, and back to the original color when they leave.
              >
              If you have every form inherit from the BaseForm, it will work the same on
              every form with no further effort on your part.
              >
              Robin S.
              -----------------------------
              "Localbar" <localbar.hk@gm ail.comwrote in message
              news:u4nkVp%23f HHA.5056@TK2MSF TNGP02.phx.gbl. ..
              Hi Robin,

              Can tell me more detail, After I create the form is no UI. and then
              how
              to do? ..No need to add textbox in baseform ?

              Thanks

              "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
              news:dKmdndWW5M XqlL7bnZ2dnUVZ_ rSjnZ2d@comcast .com ¤¤¼¶¼g...
              Create a base form that has no UI, all it does it loop through the
              controls
              on the form and set the event handlers. I would recommend using Enter
              and
              Leave instead of the Focus events, by the way.
              >
              Then have all of your forms inherit from the base form, and it will
              behave
              the same all over the place.
              >
              Robin S.
              --------------------------------
              "Localbar" <localbar.hk@gm ail.comwrote in message
              news:u2uoZO9fHH A.4692@TK2MSFTN GP03.phx.gbl...
              Hi all,

              In my form have more then 10 textbox. I would like to make all
              textbox
              when lostfocus backcolor is white, when gotfocus backcolor is yellow.
              But
              I
              don't want to write same code in the form. How to solve this problem.
              Is
              it
              can make a textbox class to control or some other method?

              Thanks


              >
              >
              >
              >

              Comment

              • RobinS

                #8
                Re: Textbox question

                Good. Glad I could help.
                Robin S.
                --------------------------
                "Localbar" <localbar.hk@gm ail.comwrote in message
                news:ObxLd0$fHH A.3676@TK2MSFTN GP05.phx.gbl...
                Thanks RobinS..It done.
                >
                "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
                news:06qdnXR1he Rru77bnZ2dnUVZ_ gGdnZ2d@comcast .com ¤¤¼¶¼g...
                >Create a form and call it something like BaseForm. Don't put any
                >controls
                >on it.
                >>
                >Put this in the code behind the form:
                >>
                >Private Sub AddEventHandler s(ByVal ctrlContainer As Control)
                > For Each ctrl As Control In ctrlContainer.C ontrols
                > If TypeOf ctrl Is TextBox _
                > OrElse TypeOf ctrl Is ComboBox Then
                > AddHandler ctrl.Enter, AddressOf ProcessEnter
                > AddHandler ctrl.Leave, AddressOf ProcessLeave
                > End If
                > 'If control has children, call this function recursively
                > If ctrl.HasChildre n Then
                > AddEventHandler s(ctrl)
                > End If
                > Next
                >End Sub
                >Private Sub ProcessEnter(By Val sender as Object, ByVal e as
                >System.EventAr gs)
                > DirectCast(send er, Control).BackCo lor = Color.Lavender
                >End Sub
                >Private Sub ProcessLeave(By Val sender as Object, ByVal e as
                >System.EventAr gs)
                > DirectCast(send er, Control).BackCo lor =
                >Color.FromKnow nColor(KnownCol or.Window)
                >End Sub
                >>
                >Add the BaseForm_Load event and put this in there:
                >>
                > AddEventHandler s(me)
                >>
                >Then create your new form, and either change it to inherit from BaseForm
                >(this is probably in the designer-generated code), or use the
                >Inheritance
                >Picker to create your new form (which does the same thing).
                >>
                >Put your textboxes on your new form, and run it, and voila! You get
                >colors
                >when you enter a textbox, and back to the original color when they
                >leave.
                >>
                >If you have every form inherit from the BaseForm, it will work the same
                >on
                >every form with no further effort on your part.
                >>
                >Robin S.
                >-----------------------------
                >"Localbar" <localbar.hk@gm ail.comwrote in message
                >news:u4nkVp%23 fHHA.5056@TK2MS FTNGP02.phx.gbl ...
                Hi Robin,
                >
                Can tell me more detail, After I create the form is no UI. and then
                how
                to do? ..No need to add textbox in baseform ?
                >
                Thanks
                >
                "RobinS" <RobinS@NoSpam. yah.none¦b¶l¥ó
                news:dKmdndWW5M XqlL7bnZ2dnUVZ_ rSjnZ2d@comcast .com ¤¤¼¶¼g...
                >Create a base form that has no UI, all it does it loop through the
                controls
                >on the form and set the event handlers. I would recommend using Enter
                >and
                >Leave instead of the Focus events, by the way.
                >>
                >Then have all of your forms inherit from the base form, and it will
                >behave
                >the same all over the place.
                >>
                >Robin S.
                >--------------------------------
                >"Localbar" <localbar.hk@gm ail.comwrote in message
                >news:u2uoZO9fH HA.4692@TK2MSFT NGP03.phx.gbl.. .
                Hi all,
                >
                In my form have more then 10 textbox. I would like to make all
                textbox
                when lostfocus backcolor is white, when gotfocus backcolor is
                yellow.
                But
                I
                don't want to write same code in the form. How to solve this
                problem.
                Is
                it
                can make a textbox class to control or some other method?
                >
                Thanks
                >
                >
                >>
                >>
                >
                >
                >>
                >>
                >
                >

                Comment

                Working...