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 get control of selected component.

How to get control of selected component.

Scheduled Pinned Locked Moved C#
csharphelptutorial
5 Posts 3 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.
  • S Offline
    S Offline
    suveenmohan
    wrote on last edited by
    #1

    Hi All, Here i develop a C# Application, in that App. I've 3 Textboxes and 2 Buttons, Default cursor set on TextBox1 and check some condition on TextBox1 Leave. But the problem is that after starting App. I wish to close that App. through Exit Button, but at that time cursor inside TextBox1 so it execute OnLeave function 1st and then I've to again click on Exit button, But i want when I clike on Exit Button in that case OnLeave function will not execute. How it is posible if any one know plz reply. Welcome any tips... Thanx & Regards SMK

    A A 2 Replies Last reply
    0
    • S suveenmohan

      Hi All, Here i develop a C# Application, in that App. I've 3 Textboxes and 2 Buttons, Default cursor set on TextBox1 and check some condition on TextBox1 Leave. But the problem is that after starting App. I wish to close that App. through Exit Button, but at that time cursor inside TextBox1 so it execute OnLeave function 1st and then I've to again click on Exit button, But i want when I clike on Exit Button in that case OnLeave function will not execute. How it is posible if any one know plz reply. Welcome any tips... Thanx & Regards SMK

      A Offline
      A Offline
      Arun Immanuel
      wrote on last edited by
      #2

      Create a flag and make it false when the user clicks the exit button. In the onleave function, first check if the flag is true or not.

      Regards, Arun Kumar.A

      S 1 Reply Last reply
      0
      • A Arun Immanuel

        Create a flag and make it false when the user clicks the exit button. In the onleave function, first check if the flag is true or not.

        Regards, Arun Kumar.A

        S Offline
        S Offline
        suveenmohan
        wrote on last edited by
        #3

        Hi, Thanx for ur reply, But my pointer is already in TextBox1 and when I click on Exit button at that time OnLeave event is fired so its not posible to set a flag on exit button in my view I've to check that component(Exit Button)at OnLeave Function. Thanx & Regrsds SMK :doh:

        A 1 Reply Last reply
        0
        • S suveenmohan

          Hi, Thanx for ur reply, But my pointer is already in TextBox1 and when I click on Exit button at that time OnLeave event is fired so its not posible to set a flag on exit button in my view I've to check that component(Exit Button)at OnLeave Function. Thanx & Regrsds SMK :doh:

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          As U have only 5 controls in Ur form, better try this: Create a member as follows: TextBox LastBox; For the OnLeave event of 3 textboxes,write like this:

          Text1_OnLeave()
          {
          LastBox=TextBox1;//Similar assignment in the other 2 textboxes.
          }

          For the OnLeave event of other controls,assign null to the member "LastBox". Create a function as follows: =============================

          Validate()
          {
          if(LastText==TextBox1)
          {
          Code to validate Textbox1.
          }
          else if(LastText==TextBox2)
          {
          Code to validate Textbox2.
          }
          else if(LastText==TextBox3)
          {
          Code to validate Textbox3.
          }
          }

          Call the "Validate" function in the OnEnter event of all the controls, except ExitButton. If U R not able to find a better solution, use this.

          Regards, Arun Kumar.A

          1 Reply Last reply
          0
          • S suveenmohan

            Hi All, Here i develop a C# Application, in that App. I've 3 Textboxes and 2 Buttons, Default cursor set on TextBox1 and check some condition on TextBox1 Leave. But the problem is that after starting App. I wish to close that App. through Exit Button, but at that time cursor inside TextBox1 so it execute OnLeave function 1st and then I've to again click on Exit button, But i want when I clike on Exit Button in that case OnLeave function will not execute. How it is posible if any one know plz reply. Welcome any tips... Thanx & Regards SMK

            A Offline
            A Offline
            AFSEKI
            wrote on last edited by
            #5
            1. Don't check string.IsNullOrEmoty condition "if it is not necessary (acceptable for values which may be left empty)" which is "I think" true for your TextBox1 with Default cursor OR 2) Don't set default cursor on your TextBox1 when the parent Form is activated (Shown, Selected...) OR 3) update a text changed flag to true in TextBox.TextChanged event and use: if(_boolTextChanged == true) { Validate(); // write your validation code here } else { return; // The user hasn't done anything, why make him/her crazy, DON'T validate anything!!! } 4) I prefer validating everything in one function when the user is finished with all modifications and presses for example the Submit Button which does not break down the nerve system of the user hearing a BEEP sound or ToolTip warning if the validation fails for the control he/she is currently modifying.
            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