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. Windows Forms
  4. Retaining Focus in owned Forms

Retaining Focus in owned Forms

Scheduled Pinned Locked Moved Windows Forms
helpbeta-testingquestioncode-review
6 Posts 2 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.
  • T Offline
    T Offline
    TyrionTheImp
    wrote on last edited by
    #1

    Hi , I`ve just hit an interesting roadblock in my app & would really appreciate any help / feedback. The "bug" can be replicated easily. Basically, I have 2 forms running as 2 different processes , say Form X & Form Y. Their properties are : Form X : ShowinTaskbar = true , FixedToolWindow , Maximized. Form Y : Showintaskbar = false , Borderstyle.None , Normal We have methods on Form Y that can be invoked via Remoting to do Show(owner) , usually Form X ends up being the owner here. I`ve impleneted the IWin32Window interface and initialise it with my Form X`s handle (obtained via FindWindow) The issue is that Form Y can NEVER retain focus (say when u click on a text box in it) and focus always gets transferred to the owner Form X. I`m not really setting an Owner / Owned relationship between them formally, say , via AddOwnedForms in Form X or Form.Owner = FormX since i guess this doesnt work across processes. If we change the ShowInTaskbar property of Form X to false , or Form Y to true then there is no problem with the Focus. Can someone please suggest where i`m going wrong or if theres any other action i need to do ? I dont really understand how the ShowinTaskbar property is affecting the focus mechanism , or whether this is how windows itself works. So far i`ve tried doing a Activate() , Focus() & BringtoFront() in Form Y but it doesnt work. SetParent isnt an option since it couples together their lifetimes i.e. if child crashes parent also crashes. Thanks in advance

    X 1 Reply Last reply
    0
    • T TyrionTheImp

      Hi , I`ve just hit an interesting roadblock in my app & would really appreciate any help / feedback. The "bug" can be replicated easily. Basically, I have 2 forms running as 2 different processes , say Form X & Form Y. Their properties are : Form X : ShowinTaskbar = true , FixedToolWindow , Maximized. Form Y : Showintaskbar = false , Borderstyle.None , Normal We have methods on Form Y that can be invoked via Remoting to do Show(owner) , usually Form X ends up being the owner here. I`ve impleneted the IWin32Window interface and initialise it with my Form X`s handle (obtained via FindWindow) The issue is that Form Y can NEVER retain focus (say when u click on a text box in it) and focus always gets transferred to the owner Form X. I`m not really setting an Owner / Owned relationship between them formally, say , via AddOwnedForms in Form X or Form.Owner = FormX since i guess this doesnt work across processes. If we change the ShowInTaskbar property of Form X to false , or Form Y to true then there is no problem with the Focus. Can someone please suggest where i`m going wrong or if theres any other action i need to do ? I dont really understand how the ShowinTaskbar property is affecting the focus mechanism , or whether this is how windows itself works. So far i`ve tried doing a Activate() , Focus() & BringtoFront() in Form Y but it doesnt work. SetParent isnt an option since it couples together their lifetimes i.e. if child crashes parent also crashes. Thanks in advance

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      As far as i understand your problem that is when you call formY then it shows behind the formX or lost focus when you click on its controls if yes then you can solve it by 3 ways 1.use ShowDialog() 2. before calling FormY then set its TopMost property to true (perhaps it work) 3. write this.Focus() in Deactivate event of FormY

      Becoming Programmer...

      T 1 Reply Last reply
      0
      • X Xmen Real

        As far as i understand your problem that is when you call formY then it shows behind the formX or lost focus when you click on its controls if yes then you can solve it by 3 ways 1.use ShowDialog() 2. before calling FormY then set its TopMost property to true (perhaps it work) 3. write this.Focus() in Deactivate event of FormY

        Becoming Programmer...

        T Offline
        T Offline
        TyrionTheImp
        wrote on last edited by
        #3

        Hi xmen_xwk , many thanks 4 ur reply. Right now Form Y is being shown , thats not an issue. Actually what i`m trying todo here is make a set of Forms work together and we can interact with any form at any time even though they are in separate exe`s. For eg: , do like minimize together , toggle between various owned forms(1 owner form is controlling a set of other owned form`s being shown or hidden),display them in a predefined part of the screen etc.. * showdialog() is a good idea but if i do it then i must close the Form Y and only then i can interact with Form X right ? so the blocking call causes problems * Plus doing this.focus() in deactivate means i can never transfer control away from Form Y :) * All the forms are non-topmost bcoz then they will then be minimized and restored together. Would u suggest changing the TopMost value on various events like OnMinimize or LostFocus ? that sounds promising.will try that Theres a "hack" i`ve tried as below with some dummy form A : Form A (grand-owner) : Form X (Owner) : Form Y (Owned) All are topmost=false , Showintaskbar = true only for Form X and is false for others. This helps solve the Keyboard focus problem , but i cant really put a "dummy form" into the actual production system code. If its ok with u I could also mail a copy of the sample project for this issue.

        X 1 Reply Last reply
        0
        • T TyrionTheImp

          Hi xmen_xwk , many thanks 4 ur reply. Right now Form Y is being shown , thats not an issue. Actually what i`m trying todo here is make a set of Forms work together and we can interact with any form at any time even though they are in separate exe`s. For eg: , do like minimize together , toggle between various owned forms(1 owner form is controlling a set of other owned form`s being shown or hidden),display them in a predefined part of the screen etc.. * showdialog() is a good idea but if i do it then i must close the Form Y and only then i can interact with Form X right ? so the blocking call causes problems * Plus doing this.focus() in deactivate means i can never transfer control away from Form Y :) * All the forms are non-topmost bcoz then they will then be minimized and restored together. Would u suggest changing the TopMost value on various events like OnMinimize or LostFocus ? that sounds promising.will try that Theres a "hack" i`ve tried as below with some dummy form A : Form A (grand-owner) : Form X (Owner) : Form Y (Owned) All are topmost=false , Showintaskbar = true only for Form X and is false for others. This helps solve the Keyboard focus problem , but i cant really put a "dummy form" into the actual production system code. If its ok with u I could also mail a copy of the sample project for this issue.

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          buddy your problem is strange for me because i still not understood what is the problem and what are you trying to do.... if you explain exact what you want (if you like) then it will be better to understand. i just understood that you want to interact in all 3 forms....

          Becoming Programmer...

          T 1 Reply Last reply
          0
          • X Xmen Real

            buddy your problem is strange for me because i still not understood what is the problem and what are you trying to do.... if you explain exact what you want (if you like) then it will be better to understand. i just understood that you want to interact in all 3 forms....

            Becoming Programmer...

            T Offline
            T Offline
            TyrionTheImp
            wrote on last edited by
            #5

            hi , just tried the options u`ve suggested... unfortunately the problem still remains :( ShowDialog() works but then i must close that form before interacting with any other forms. Was the sample i uploaded useful ?

            X 1 Reply Last reply
            0
            • T TyrionTheImp

              hi , just tried the options u`ve suggested... unfortunately the problem still remains :( ShowDialog() works but then i must close that form before interacting with any other forms. Was the sample i uploaded useful ?

              X Offline
              X Offline
              Xmen Real
              wrote on last edited by
              #6

              did you try Show()? if yes then try again, after enable the topmost of the form

              Becoming Programmer...

              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