c# - SetWindowPos not working on Form.Show() -


i calling form.show() on form , stuff afterwards causes updates on shown form.

i want move window form location process during time setwindowpos. sadly calling of setwindowpos nothing. because never idling?

any idea solve problem?

thank you

edit: code:

main.show(); main.initbase(); //takes 2-3 seconds main.hidemainform(); //moves form (10000, 10000), hide (can't change it's old programm) 

at main.shown event have call program calls setwindowpos(pd.currenthandle, hwnd_topmost, r.x, r.y, r.width, r.height, setwindowposflags.donotchangeownerzorder);

where r rectangle of selected display

i tried

eventhandler ev = new eventhandler((s, e) => {     main.close(); ev = new eventhandler((s2, e2) => { }); });  main.shown += ev;         main.showdialog(); main.show(); 

which works fine ugly code , trying find better solution.

two possibilities come mind.

first, @ main.shown, external program calls setwindowpos move window. , code shows form takes 2 or 3 seconds initialize , moves window off screen. possible external program calls setwindowpos executing before call hidemainform?

what happens if comment out hidemainform? window moved?

second, have:

setwindowpos(     pd.currenthandle,      hwnd_topmost,     r.x, r.y, r.width, r.height,     setwindowposflags.donotchangeownerzorder); 

it might donotchangeownerzorder flag interfering hwnd_topmost request, , function failing. documentation says:

a window can made topmost window either setting hwndinsertafter parameter hwnd_topmost , ensuring swp_nozorder flag not set, or setting window's position in z order above existing topmost windows. when non-topmost window made topmost, owned windows made topmost. owners, however, not changed.

granted, doesn't swp_noownerzorder flag, in general case owner's z order change if placed above it. if request flag , function can't ensure it, function might fail.

you need check return value of setwindowpos:

bool success = setwindowpos(...); if (!success) {     int err = marshal.getlastwin32error();     // err value give information why failed. } 

for work, dllimport must have setlasterror=true.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -