Results 1 to 6 of 6

Thread: Loading a form without displaying it

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    9

    Loading a form without displaying it

    I need to have a form load, but not display until it is ready (some maths heavy calculations need to be done before the form can display). As I understand it, the only way to trigger the load event in a form is by Form.Show(). Is there another way to do it without the form becoming visible? I have played around with Form.Activate(), but haven't had any luck yet.

    Thanks,
    Vulpes

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Why not set it's visable property to false, and then use form.show() and when ready, make it visable?

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why do you need the Form_Load event?

    Any initialization code can go in the constructor. If you expand the 'Windows Form Designer generated code' region at the top of the form. Look for the constructor:

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    End Sub

    Then just put your code in the spot it suggests after the InitializeComponent call.

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    just do something like this ...
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         While DoStuff() = False
    3.             Application.DoEvents() '/// dont allow the Form to show till DoStuff = True.
    4.         End While
    5.     End Sub
    6.  
    7.     Private Function DoStuff() As Boolean
    8.         MessageBox.Show("wait for form to load") '/// your stuff ToDo before Form shows goes here.
    9.         Threading.Thread.Sleep(5000) '/// 5 seconds in this case.
    10.         Return True
    11.     End Function


    edit :
    by the way you dont need to use Sleep when actually carrying out the function, that was just to demonstrate. you would do this...
    VB Code:
    1. Private Function DoStuff() As Boolean
    2.         '/// carry out the code before loading the form.
    3.         Return True
    4.     End Function
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    My vote and prefered method would be to do it in the constructor, as Edneeis suggested.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    9
    Ah wonderful, thanks Edneeis. I am upgrading the program from VB6, and it didn't even occur to me to use the constructor instead of the load event. Thanks to everyone.

    -Vulpes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width