none
Initialize values at program start, before the form is displayed

    Question

  • I have a simple Windows Forms program in Visual Basic. I would like to initialize some values both on the displayed form and in a Folder Browser dialog, before the main form is displayed. How do I do this?
    Sunday, January 05, 2014 1:43 AM

Answers

All replies

  • Initialize them in Form_Load Event

    Also refer this http://msdn.microsoft.com/en-us/library/86faxx0d%28v=vs.110%29.aspx


    Sunday, January 05, 2014 5:52 AM
  • In addition to Mahindar, if we handle your question like you ask then using the on load event like he wrote is the most common way in VB. 

    However, in VB is in windows forms the constructor default in the framework and not given standard in code like in C#  

    But that does not mean you cannot use it in VB.

    You can create in every form code a Sub New and then put in that a call to InitializeComponent. In that way you can even before the initialization of the form add code.

    I don't advice you that constructor way, but as addition for those who are searching for a likewise way like in C#


    Success
    Cor

    Sunday, January 05, 2014 9:51 AM
  • Just to clarify: 

    If your [Form] class has no other constructors, then Visual basic will "write" one of its own, for its own use.  As soon as you code any constructor yourself, then the generated, default one is no longer .. er .. generated (and is effectively removed).  This can cause some "interesting" (and downright confusing) side-effects. 

    I would recommend you get into the habit of writing your own, default constructor in all your Form classes.



    Regards, Phill W.

    Tuesday, January 14, 2014 12:57 PM
  • Just to clarify:

    Do you mean: If I write any constructor, VB writes no constructors at all or do you mean VB writes all constructors except the one I was brave enough to write?

    Speaking of courage, could you direct me to documentation on how to write a proper constructor for -- in my case -- the Form Browser Dialog?

    Thanks,

    Mike K

    Wednesday, January 15, 2014 1:57 AM
  • I know little.

    at compile time the compiler checks for constructor if there is no constructor it creates a implicit constructor.Check this link

    Write this code in form_Load event or constructor to set the default folder

                folderBrowserDialog1.SelectedPath = "e:\\test\\test2";


               

    Wednesday, January 15, 2014 5:30 AM
  • Just to clarify:

    Do you mean: If I write any constructor, VB writes no constructors at all or do you mean VB writes all constructors except the one I was brave enough to write?

    Speaking of courage, could you direct me to documentation on how to write a proper constructor for -- in my case -- the Form Browser Dialog?

    Thanks,

    Mike K

    A strange thing every MVP want to be changed, but Microsoft refuses to make this the same as in C#.

    Go to Solution explorer and mark Show All Files. 

    Now you can find your constructor is in the yourprogramname.designer.vb file.

    I think Microsoft wants once to be responsible if this goes wrong because you have to be careful in this VB way and not in the C# way.


    Success
    Cor

    Wednesday, January 15, 2014 1:47 PM