2013-10-17 41 views

回答

10

可以插入下面的代码到窗体的公告称,形式已经打开init方法。 如果您有任何问题的代码不要犹豫,问!

public void init() 
{ 
    #define.CACHE_OWNER  ('MyForm') 
    #define.CACHE_KEY_INSTANCE ('Instance') 

    FormRun existingForm() 
    { 
     ; 

     if (infolog.globalCache().isSet(#CACHE_OWNER, #CACHE_KEY_INSTANCE)) 
     { 
      return infolog.globalCache().get(
       #CACHE_OWNER, #CACHE_KEY_INSTANCE); 
     } 
     return null; 
    } 

    void registerThisForm() 
    { 
     ; 

     infolog.globalCache().set(#CACHE_OWNER, #CACHE_KEY_INSTANCE, this); 
    } 

    boolean isAlreadyOpened() 
    { 
     ; 

     return existingForm() ? !existingForm().closed() : false; 
    } 

    void activateExistingForm() 
    { 
     ; 

     existingForm().activate(true); 
    } 
    ; 

    super(); 
    if (isAlreadyOpened()) 
    { 
     activateExistingForm(); 
     this.close(); 
    } 
    else 
    { 
     registerThisForm(); 
    } 
} 
+1

这很好用。我确实必须将activate方法更改为element.existingForm()。setActive(); activate()命令没有将原始表单放在前面。非常感谢! – Brad

0

下面的代码添加到形式的init方法如下。不需要其他更改。

public void init() 
{ 
    #define.CACHE_OWNER('MyForm') 
    int hWnd; 

    super(); 

    if (infolog.globalCache().isSet(#CACHE_OWNER, curUserId())) 
    { 
     hWnd = infolog.globalCache().get(#CACHE_OWNER, curUserId()); 
    } 

    if (WinApi::isWindow(hWnd)) 
    { 
     element.closeCancel(); 
     WinAPI::bringWindowToTop(hWnd); 
    } 
    else 
    { 
     infolog.globalCache().set(#CACHE_OWNER, curUserId(), element.hWnd()); 
    } 
}