Save excel workbook form always on top c# -


i'm creating new excel file c#, @ end need open form save it, @ moment window opens behind application.

is there way open on top?

here code:

excel.application _xlapp;  _xlapp.activewindow.activate(); _xlworkbook.close(true, type.missing, type.missing); _xlapp.quit(); _xlapp = null; 

we use next helper class purpose:

public class processmanager {     private intptr _buffer = intptr.zero;     private intptr _hwnd = intptr.zero;     private string _filenamemarker;      public void startassiciatedprocessandbringittofront(string filename, string filenamemarker)     {         if (string.isnullorempty(filename))             throw new argumentexception();          _filenamemarker = filenamemarker;          try         {             process.start(filename);              if (!string.isnullorempty(_filenamemarker))             {                 _buffer = intptr.zero;                 _hwnd = intptr.zero;                  _buffer = marshal.allochglobal(512);                 nativehelpers.enumwindows(new nativehelpers.enumwindowsproc(searcher), intptr.zero);                  if (_hwnd != intptr.zero)                 {                     bringtofront(_hwnd);                 }             }         }                 {             if (_buffer != intptr.zero)             {                 marshal.freehglobal(_buffer);                 _buffer = intptr.zero;             }              _hwnd = intptr.zero;             _filenamemarker = null;         }     }      private int searcher(intptr hwnd, intptr lparam)     {         int result;         int ok = nativehelpers.sendmessagetimeout(hwnd,                                                   nativehelpers.wm_gettext,                                                   new intptr(250),                                                   _buffer,                                                   nativehelpers.smto_block | nativehelpers.smto_abortifhung,                                                   100,                                                   out result);         if (ok == 0)             return 1; // ignore , continue          if (result > 0)         {             string windowname = marshal.ptrtostringauto(_buffer);             if (windowname.contains(_filenamemarker))             {                 _hwnd = hwnd;                 return 0; // stop search             }         }          return 1; // continue     }      private static void bringtofront(intptr hwnd)     {         if (nativehelpers.isiconic(hwnd) != 0)             nativehelpers.showwindowasync(hwnd, nativehelpers.sw_restore);         nativehelpers.setforegroundwindow(hwnd);     }      public void startassiciatedprocessandbringittofront(string filename)     {         if (string.isnullorempty(filename))             throw new argumentexception();          try         {             var p = process.start(filename);             p.waitforinputidle(5 * 1000);             _hwnd = p.mainwindowhandle;              if (_hwnd != intptr.zero)             {                 bringtofront(_hwnd);             }         }         catch         {         }     } } 

you can use startassiciatedprocessandbringittofront method.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -