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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to give the focus back to the caller form?

How to give the focus back to the caller form?

Scheduled Pinned Locked Moved C#
helptutorialquestion
6 Posts 4 Posters 4 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
    sapnabn
    wrote on last edited by
    #1

    Hi, I have a smal problem, but needs immediate resolution. I have an MDI application through which i opens a form; say "Form1". From "Form1" I am calling another form; say "Form2". Now, when clicking a button in "Form2", I need the focus to be given back to the original "Form1".ie, I need "Form1" to be activated. Somebody please help me in doing this..... Thanks Sapna:)

    C S 3 Replies Last reply
    0
    • S sapnabn

      Hi, I have a smal problem, but needs immediate resolution. I have an MDI application through which i opens a form; say "Form1". From "Form1" I am calling another form; say "Form2". Now, when clicking a button in "Form2", I need the focus to be given back to the original "Form1".ie, I need "Form1" to be activated. Somebody please help me in doing this..... Thanks Sapna:)

      C Offline
      C Offline
      codes w
      wrote on last edited by
      #2

      In form2, u put the following code within the button click event Response.Redirect("form1 with extension"); Try it

      A 1 Reply Last reply
      0
      • C codes w

        In form2, u put the following code within the button click event Response.Redirect("form1 with extension"); Try it

        A Offline
        A Offline
        Al Gardner
        wrote on last edited by
        #3

        codes/w wrote: Response.Redirect("form1 with extension"); Which I am sure this works for a web application, but for a System.Windows.Forms application, try void Form2_button1_click(object sender, eventargs e) { Form1.Focus(); } Be aware that if you have opened the Dialog modally (i.e. from form1 you called form2.ShowDialog()) then the focus will stay in Form2.

        C 1 Reply Last reply
        0
        • A Al Gardner

          codes/w wrote: Response.Redirect("form1 with extension"); Which I am sure this works for a web application, but for a System.Windows.Forms application, try void Form2_button1_click(object sender, eventargs e) { Form1.Focus(); } Be aware that if you have opened the Dialog modally (i.e. from form1 you called form2.ShowDialog()) then the focus will stay in Form2.

          C Offline
          C Offline
          codes w
          wrote on last edited by
          #4

          Ooh, thanks alot

          1 Reply Last reply
          0
          • S sapnabn

            Hi, I have a smal problem, but needs immediate resolution. I have an MDI application through which i opens a form; say "Form1". From "Form1" I am calling another form; say "Form2". Now, when clicking a button in "Form2", I need the focus to be given back to the original "Form1".ie, I need "Form1" to be activated. Somebody please help me in doing this..... Thanks Sapna:)

            S Offline
            S Offline
            Stanciu Vlad
            wrote on last edited by
            #5

            I have a very simple and easy to use solution for you simply pass the parent form as a parameter in the constructor of the second one (I think that any window (especialy MDI) has a parent property thow) and when you desire call myParentForm.Activate(); (or more professional (but recomandede in a try\catch) this.Parent.Activate(); I hope you understand... By the way... visit http://nehe.gamedev.net[^]

            1 Reply Last reply
            0
            • S sapnabn

              Hi, I have a smal problem, but needs immediate resolution. I have an MDI application through which i opens a form; say "Form1". From "Form1" I am calling another form; say "Form2". Now, when clicking a button in "Form2", I need the focus to be given back to the original "Form1".ie, I need "Form1" to be activated. Somebody please help me in doing this..... Thanks Sapna:)

              S Offline
              S Offline
              Stanciu Vlad
              wrote on last edited by
              #6

              call the forms parent activate procedure this.Parent.Activate() or give the second form an argument (the main form) class Form2 { Form1 myParentForm; ... Form2 (Form1 parent) { ... myParentForm = parent; ... } ... this.myParentForm.Activate(); ... } I hope you understand... By the way... visit http://nehe.gamedev.net[^]

              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