none
what is the alternative for VB6 load method in VB.Net? RRS feed

Answers

  • As with many of the VB 6.0 extensions there isn't a direct equivalent in .NET. That is why we generally need to know what you are trying to accomplish in order establish a workaround.

    If you want the form to be loaded, but not visible then add the following code to the form:

        Protected Overrides Sub SetVisibleCore(ByVal value As Boolean)
            If Not Me.IsHandleCreated Then
                Me.CreateHandle()
                value = False
            End If
            MyBase.SetVisibleCore(value)
        End Sub


    Paul ~~~~ Microsoft MVP (Visual Basic)


    • Marked as answer by adushetty Wednesday, May 23, 2018 7:01 PM
    • Edited by Paul P Clement IV Wednesday, May 23, 2018 7:49 PM missing word
    Wednesday, May 23, 2018 2:18 PM

All replies

  • Do you want them all or only one?

    If it is a file then for instance 

    Io.File.ReadFile

    https://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx

    But there is much more for files. 

    If it is a control then simply 

    Controls.Add(thenameofTheControl)

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.remove(v=vs.110).aspx

    If it is a form then

    TheNewForm = new TheNameOfTheFormClass
    TheNewForm.Show


    Success
    Cor




    Tuesday, May 22, 2018 8:46 PM
  • According to this documentation, that "Load" method was for adding a new element to a control array.  Control arrays do not exist as such in .Net so there would not be an equivalent.

    What precisely are you trying to do?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 22, 2018 8:55 PM
    Moderator
  • I know form. show(). but the situation is like this.

    I am migrating Vb6 ActiveX control to Vb.net console application.

    basically, the form should not appear on the screen. since it's a console application it should run in the back ground.

    In VB6, the Load function used to just load the form and it doesn't show the form to user. I am looking something same in vb.net

    Tuesday, May 22, 2018 8:57 PM
  • There are no forms in a console application...  I'm not sure how an ActiveX control could be translated to a console project...

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 22, 2018 8:58 PM
    Moderator
  • forget about console application, tell me how to do it in windows application
    Tuesday, May 22, 2018 9:01 PM
  • Just create the form instance but don't call the show method.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 22, 2018 9:04 PM
    Moderator
  • ActiveX controls were never a part of VB. In VB6 it where mostly 3rd party solutions. 

    However, ActiveX is ended for Microsoft, not only for VB. 

    Therefore the best chance you have is looking for newer 3rd party solutions. 

    https://www.infragistics.com/products/ultimate


    Success
    Cor


    Tuesday, May 22, 2018 9:08 PM
  • If you are talking about the main form then you would need to let the form load and then hide it after it finished loading.

    -edit-

    Something like this:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BeginInvoke(Sub()
                        Me.Hide()
                    End Sub)
    End Sub
    

    But are you sure you don't actually want to create a control library instead of an application?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Tuesday, May 22, 2018 9:09 PM
    Moderator
  • forget about console application, tell me how to do it in windows application

    I think you can use startup with sub main. You can set this application setting in the project properties for the startup form but you select sub Main.

    That will start you in a code module with no form and you can then run other processes.

    Or possibly you mean old include functions to load code modules I forget what they were called.

    Wednesday, May 23, 2018 7:13 AM
  • @Tommy,

    I too explored this option for the OP, however, without a Form started via Application.Run, there is nothing to keep the program running.  They would have to implement some kind of loop, or as you say, launch some other process.  At that point they might as well use a console application.

    The only valid thing I can think of to translate an ActiveX control into .Net would be to create a control library and then reference that from another project.  Since they talk about "not visible/run in background" it sounds like the "control" is actually a component.

    But until/unless they provide us with more information about precisely what they are trying to convert, its all a big guessing game.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, May 23, 2018 11:20 AM
    Moderator
  • @Tommy,

    I too explored this option for the OP, however, without a Form started via Application.Run, there is nothing to keep the program running.  They would have to implement some kind of loop, or as you say, launch some other process.  At that point they might as well use a console application.

    The only valid thing I can think of to translate an ActiveX control into .Net would be to create a control library and then reference that from another project.  Since they talk about "not visible/run in background" it sounds like the "control" is actually a component.

    But until/unless they provide us with more information about precisely what they are trying to convert, its all a big guessing game.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    That was my conclusion as well. But my experience is that persons who still in 2018 use ActiveX don't like that conclusion.

    :-)


    Success
    Cor

    Wednesday, May 23, 2018 11:38 AM
  • @Tommy,

    I too explored this option for the OP, however, without a Form started via Application.Run, there is nothing to keep the program running.  They would have to implement some kind of loop, or as you say, launch some other process.  At that point they might as well use a console application.

    The only valid thing I can think of to translate an ActiveX control into .Net would be to create a control library and then reference that from another project.  Since they talk about "not visible/run in background" it sounds like the "control" is actually a component.

    But until/unless they provide us with more information about precisely what they are trying to convert, its all a big guessing game.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    That was my conclusion as well. But my experience is that persons who still in 2018 use ActiveX don't like that conclusion.

    :-)


    Success
    Cor

    Well the only other thing not mentioned that is in .net would be a .dll.

    I started my vb app with Sub Main for years. Of course it did some things to setup and then ran in a do loop with a do events.

    I think the key now is knowing what the activex code does and why.

    Wednesday, May 23, 2018 12:57 PM
  • Well the only other thing not mentioned that is in .net would be a .dll.

    Actually that has been said like three times, just not with the acronym "dll".  :) ;) :D

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, May 23, 2018 1:34 PM
    Moderator
  • As with many of the VB 6.0 extensions there isn't a direct equivalent in .NET. That is why we generally need to know what you are trying to accomplish in order establish a workaround.

    If you want the form to be loaded, but not visible then add the following code to the form:

        Protected Overrides Sub SetVisibleCore(ByVal value As Boolean)
            If Not Me.IsHandleCreated Then
                Me.CreateHandle()
                value = False
            End If
            MyBase.SetVisibleCore(value)
        End Sub


    Paul ~~~~ Microsoft MVP (Visual Basic)


    • Marked as answer by adushetty Wednesday, May 23, 2018 7:01 PM
    • Edited by Paul P Clement IV Wednesday, May 23, 2018 7:49 PM missing word
    Wednesday, May 23, 2018 2:18 PM