Results 1 to 6 of 6

Thread: Show/Hide a form in form_load (Resolved)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Victoria, Australia
    Posts
    23

    Show/Hide a form in form_load (Resolved)

    I have two forms - frmmain, and form1

    Under frmmain, I'm using a If/Then/Else statement checking a variable value.
    Frmmain is the startup form.

    VB Code:
    1. Dim form1 as new form1
    2.  
    3. If Val = "1" Then
    4. 'do nothing
    5. Else
    6. form1.visible = True
    7. frmmain.visible = False
    8. End If

    form1 will always show, but frmmain won't hide. I've tested this using just one form and just putting me.visible = false. I've tried me.hide, I've tried putting the code behind a timer and enabling the timer from form_load, I've tried calling a new sub from form_load, but NOTHING I do seems to work.

    Does anyone know what I'm doing wrong?
    Last edited by DestructoX; Mar 23rd, 2004 at 01:33 AM.
    Logic is a systematic way of coming to the wrong conclusion with confidence.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yeah you are trying to hide a form in the load event. You should check your condition without loading the form and then only load it if it will show.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Victoria, Australia
    Posts
    23
    The only way I know of doing that is by using Sub Main, but I'm not really familiar with it.
    Logic is a systematic way of coming to the wrong conclusion with confidence.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why does the form need to be used? What is it you are trying to do? If you ask more specific questions we can help more. To use Sub Main (this may or may not be the best way depending on what you are trying to do) you change the startup in the project properties to Sub Main. Then make a Sub Main method either in a class, module, or the form.
    VB Code:
    1. Public Class Startup
    2.  
    3.   Public Sub Main()
    4.      'do check here
    5.     If Check=True Then
    6.         Application.Run(New frmMain)
    7.     Else
    8.        'do something else
    9.        Application.Run(New frmAlternate)
    10.     End If
    11.   End Sub
    12.  
    13. End If

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Victoria, Australia
    Posts
    23
    I've got frmmain and form1

    Form1 is basically a wizard to configure some settings.

    When the program loads, it uses GetSetting to check wether the value Run = 1. If it doesn't, it hides that form and shows the wizard. If it does, it just continues

    I'll try out the above code and see what happens
    Logic is a systematic way of coming to the wrong conclusion with confidence.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    Victoria, Australia
    Posts
    23
    OK, That code for Sub Main worked. Thanks a heap.
    Logic is a systematic way of coming to the wrong conclusion with confidence.

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