c# - Main form is always stealing focus, when child form is created out of treeView -


i've following problem: program (winforms) has main window treeview control. when user selects node in treeview new child window shall created.

this works fine. problem is, after child window has become visible, main window comes front , partially hides child window.

i've build little mockup in order make sure not related program:

namespace fatherandson {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }      private void button1_click(object sender, eventargs e)     {         son anewson = new son();         anewson.visible = true;     }      private void treeview1_afterselect(object sender, treevieweventargs e)     {         son anewson = new son();         anewson.visible = true;     } } } 

when press button1, fine when select node in treeview, main window jumps front after child form appeared.

what wrong?

change visible = true .show(this) -> change make child window on top of it's parent (main window in case).

son anewson = new son(); anewson.show(this); 

if not acceptable child form on top of it's parent change to:

son anewson = new son(); anewson.visible = true; anewson.focus(); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -