Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to disable the GotFocus on textbox?

how to disable the GotFocus on textbox?

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gali1978
    wrote on last edited by
    #1

    i have textbox that do something on GotFocus. how i can disable the GotFocus on this textbox ? and how to enable it back ? thanks in advance

    M X L 3 Replies Last reply
    0
    • G Gali1978

      i have textbox that do something on GotFocus. how i can disable the GotFocus on this textbox ? and how to enable it back ? thanks in advance

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Presumably you are talking winforms! GotFocus is an event, you can't disable it, you can disable the control or you can handle the problem inside the event.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • G Gali1978

        i have textbox that do something on GotFocus. how i can disable the GotFocus on this textbox ? and how to enable it back ? thanks in advance

        X Offline
        X Offline
        xavjer
        wrote on last edited by
        #3

        if you want to disable a textbox, you can use

        textbox.enable = false;

        and true to reanable it ofc. If you don't like this solution, you can try to overwrite the GotFocus method to only do "something" if you want it.

        1 Reply Last reply
        0
        • G Gali1978

          i have textbox that do something on GotFocus. how i can disable the GotFocus on this textbox ? and how to enable it back ? thanks in advance

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Gali1978 wrote:

          how i can disable the GotFocus on this textbox ?

          textBox1.GetFocus -= this.textBox1_GotFocus;

          Gali1978 wrote:

          and how to enable it back ?

          textBox1.GetFocus += this.textBox1_GotFocus;

          Alternatively, you could set a flag to indicate your "disabledness" and act on that;

          bool isFocusEnabled = false;

          void this.textBox1_GotFocus(object sender, EventArgs e)
          {
          if (!isFocusEnabled) then return; // exit the method if the flag is set
          }

          That'd allow you to disable/enable the execution of the event with a simple boolean.

          Bastard Programmer from Hell :suss:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups