Locked Problems calling a VB6 form modal in VB.NET

  • 2008年10月2日 12:11
     
      コードあり
    Hello,

    we have a little problem with calling a vb6 form modal on a a vb.net form.

    Our scenario:
    We have a startup exe with a form at first.
    On this form the user can open subprojects. Each subproject was called in an own thread. So the user can toggle between the other subprojects and modal windows on subprojects don't lock the other windows.

    Now we want to call a VB6 ActiveX DLL/EXE out of the subproject.
    In this VB6 DLL/EXE we call a function which opens a VB6 form modal. If the VB6 component is a DLL the menuform seems to be the owner of the VB6 window. Other subprojects are not locked. But when the VB6 component is a EXE the subproject is the owner. That looks good on first view. But if you call two VB6 EXE from two different subprojects, the last one locks all previuos.

    How is it possible to call a VB6ActiveX DLL/EXE -form modal out of VB.NET that was only modal to the calling form.

    I have added a sample to eximplify here -> Sample

    Kind regards

    Björn

すべての返信

  • 2008年10月7日 2:07
    モデレータ
     
      コードあり
    Hi Björn,

    Based on your post, my understanding of your issue is that you call ActiveX component to show a VB6 form and you want to implement the above requirement.

    As far as I know, a modal form or dialog box must be closed or hidden before you can continue working with the rest of the application. In Windows Form project, you can implement the similar effect with the Owner property, I think that you need to modify your application to use this feature to satisfy your requirement. Hope this helps. If you have any further issues, feel free to tell us.

           Dim f As New Form2 
            f.Owner = Me 
            f.Show() 


    Best regards,
    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • 2008年10月7日 6:54
     
      コードあり
    Hi Riquel,

    first thank you for your reply.

    The problem is that we call the vb6 form not directly in vb.net, but call a vb6 class which opens the vb6 form:

    'VB6 class/method called from vb.net 
     
    Public Sub OpenForm(text As String
     
    Dim lForm As New Form2 
    lForm.Caption = text 
    lForm.Show vbModal 
    Unload lForm 
     
    End Sub 

    When i try to pass the vb.net form i get a typemismatch :

    'VB6 class/method called from vb.net  
      
    Public Sub OpenForm(vbnetForm as object, text As String)  
      
    Dim lForm As New Form2  
    lForm.Caption = text  
    lForm.Show vbModal, vbnetForm 
    Unload lForm  
      
    End Sub  

    As you can see in my sample its a very curious behaviour calling a vb6 form in vbnet.

    Looking forward to your reply,

    Björn





    • 編集済み moellerbj 2008年10月7日 6:56 Added the sample link
    •  
  • 2008年10月8日 12:25
    モデレータ
     
     
    Hi Björn,

    Of course we can't pass the .NET form object as the VB6 Form object. If you use Interop Form toolkit to create the Interop Form in this scenario, try it to see whether it satisfies your requirement.

    Best regards,
    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • 2008年10月14日 14:36
     
     
    Hello Riquel,

    i 've tried a bit on Interop Form Toolkit. But for me its not pssoible to get the vb6 form using the vb.net form as owner.
    I can not be impossible to call an vb6 window modal on a vb.net window.

    Searching for help furthermore,
    Björn
  • 2008年10月16日 11:03
     
     

    Hi

    It may be a silly suggestion but have you tried treating your form as a dialog and modifying your code simply to be

    lform.showdialog()

    instead of lform. show vbModal

    This would effectively display the form in a modal fashion as the dialog box must be closed before the application can continue

    Tris

  • 2008年11月3日 8:39
     
     
    Hello Tris,

    maybe it's silly ;-)

    VB6 doesn't know a ShowDialog-Method.

    Björn
  • 2008年11月4日 13:55
     
     
    Sorry Bjorn

    I didn't fully explain my thinking - have a look at this article

    http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.compatibility.vb6.support.showform.aspx

    Or maybe I completely misunderstand your intent?
  • 2011年3月21日 20:26
     
     

    I wanna know the owner of an interops form too.

    A .NET Windows Form called by a VB6 form like this:

    example_net_form.Show vbModal, Me

    Unfortunately interops forms library doesn't have the second parameter of the Show method

     

    Would it be nice if we can do this in the .Net Form for example:

    Me.Owner.Top = 10

    Has anyone have a way to do this?

     

     

     

     


  • 2011年11月22日 21:41
     
     回答の候補

    So one way that this can be done is to have an event on your .NET form. Raise that event from the .NET form and implement that event in your VB6 form. Your VB6 form can then call whatever.

    You cannot have a .NET Form set as VbModal do anything back in VB6 as that process is isolated. You can fake it by setting the ZOrder of the .NET form in VB6 when a click, double-click, or focus event is executed. Unfortunately, a VB6 form doesn't have a "focus" event.


    Microsoft MVP, ASPInsider
  • 2012年6月21日 14:43
     
     

    I know this is a really old thread, and you may be thinking "Why would you be doing that NOW - in 2012!?!".  But here we are.  I too need to interop a number of Vb6 Modal Forms that are called through a public object in a dll.

    Our application also has multiple UI threads (one per module) as described by your post and we are experiencing the same issue when calling the methods in the dll to show the forms.  Fine when called from the main Module, but on the sub-modules the modal forms fall to the back and appear to attach themselves to the Main module's form.  

    So did you ever, resolve the issue of setting the owner of the Vb6 Modal form to a .Net parent?   

    Interestingly, when showing a modal form from a class in an OCX (rather than a dll), there is no such issue, the owner is resolved successfully (which gives me some hope).  I know one solution is to recompile each dll (of which there are many) as ocxs, but this would been rebuilding a large chunk of the Vb6 code base, which is large and we have no automated build routines!

    Kind Regards


    Y Cymro

  • 2012年6月22日 8:53
     
     
    I found it...it wasn't because the ocx worked where the dll had the issue, turns out the Threading Model on the dll was set to Single rather than Apartment threaded.  Switching this back to Apartment Threaded, and all works as expected.

    Y Cymro