Results 1 to 26 of 26

Thread: Form1.close? - Believe it or not, still *unresolved*

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Form1.close? - Believe it or not, still *unresolved*

    how can you close another form?
    or show another form?

    Please see my last post in this thread..
    Last edited by VaxoP; Aug 2nd, 2003 at 04:04 PM.

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Close another form, use
    VB Code:
    1. Form1.Close()
    However, if you want the user to be able to use it again within the life of the main application, use
    VB Code:
    1. Form1.Hide()

    To show another forum, you first must declare it like
    VB Code:
    1. Dim Form1 As New Form1

    Then just use
    VB Code:
    1. Form1.Show()

    To set a form as the default, just right click on the project and click properties and then select which form to load on execution.


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    thanks

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    Dim form2 As New Form2()
    form2.Close()

    it still keeps showing up tho

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by VaxoP
    Dim form2 As New Form2()
    form2.Close()

    it still keeps showing up tho
    Uh? What keeps showing up?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    VB Code:
    1. Dim Form1 As New Form1()
    2.         Dim Form2 As New Form2()
    3.         If ActiveLock1.RegisteredUser = True Then
    4.             Form1.Show()
    5.             Form2.Close()
    6.         Else
    7.             Text1.Text = ActiveLock1.SoftwareCode
    8.             Me.Show()
    9.             Text2.Focus()
    10.         End If

    ack registereduser is true - form1 is shown but then for some reason form2 is shown as well

    if i close form2 with the X, the whole app terminates..

    theres no other references to form2

    why wont the bloody thing close? (its the startup object)

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    use form2.Hide() then, because if that's the startup object, the whole application will terminate

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    no luck
    VB Code:
    1. Dim Form1 As New Form1()
    2.         Dim Form2 As New Form2()
    3.         If ActiveLock1.RegisteredUser = True Then
    4.             Form1.Show()
    5.             Form1.Focus()
    6.             Form2.Hide()
    7.         Else
    8.             Text1.Text = ActiveLock1.SoftwareCode
    9.             Me.Show()
    10.             Text2.Focus()
    11.         End If
    12.     End Sub
    it still is visible

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    now i added a button and clicked it to try and close the damn thing thru form1 - but still it has no effect on it
    VB Code:
    1. Dim form2 As New Form2()
    2.         form2.Hide()
    3.         form2.Visible = False

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Not sure dude, what events are you putting this in? All button click events?

    Form2.Hide() should work.....

    Question, how does your program start? Does it load Form1 or does it load Form2 on execution?

    If it loads Form2 on execution, why not try it with loading Form1 on execution, then in it's loading event, show form2

    It may not like to hide the main form

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    its not that easy..

    form1 is the main form - its the actual program. form2 is a check to see if the person has registered the program. in form2 theres a serial and a keycode textbox. if the combination is right, or the right data is retrieved from the registry, the person is registered.

    all im trying to do is close the register form if the person is registerd and open the main form.. but the register form refuses to leave

  12. #12
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    I would ask you to post your project so I could see but if you need to register it, you may not want your source code out their..

    Hmm... If the main form loads (Form1) On load, why not have it go into the registery and look for a serial number, then check it to see if it's accurate, if it is it finishes loading, otherwise it locks the form and shows form2 so they can write the appropriate information to the register if it's correct....

    I don't understand why your current code won't work, I've never had any problems hiding forms, and with the program I'm writting now, I got about 5 extra forms that open and hide....

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    VB Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.         Dim form2 As New Form2()
    3.         form2.Hide()
    4.         form2.Visible = False
    5.     End Sub

    why wont that do anything?

  14. #14
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    I think you only need
    VB Code:
    1. Dim form2 As New Form2()

    To show a form but I can't remember... anyway, declare that up at the top under the automaticlly generator code VB creates.

    Like:
    VB Code:
    1. #Region " Windows Form Designer generated code "
    2.     Dim frmChild As New frmChild
    3.     Dim frmAbout As New frmAbout
    4.     Dim frmPreferances As New frmPreferances

    Well that's how it's declared in my application so I can show and hide those forms. Try declaring it in their isntead of within the Sub.

    That is probably your problem, I should of specified that.... or it may not be, I'm not exactly a pro with VB .NET (Still fairly new to it myself)

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    still no luck

    why must vb.net be so complicated - youd think a simple thing like form.hide would not be changed because it already works so well

    An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.windows.forms.dll

    Additional information: Error creating window handle.
    Last edited by VaxoP; Aug 2nd, 2003 at 03:12 PM.

  16. #16
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by VaxoP
    still no luck

    why must vb.net be so complicated - youd think a simple thing like form.hide would not be changed because it already works so well

    An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.windows.forms.dll

    Additional information: Error creating window handle.
    It isn't complicated, it works perfectly for me.... you gotta be doing something wrong.... I don't know maybe someone else can come in here and will know, that or you could always post your project but since you require registration, you may not want to...

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    heres what i think is happening

    i noticed that with
    Dim form2 As New Form2()
    form2.Hide()
    form2.Visible = False

    a NEW form2 appears for a second and then is hidden..

    but the old one (that already exists) just sits there..

    how can i fix this?

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    well, i think i kinda get how it works now

    if a form is loaded, you use
    dim x as form

    otherwise, use dim x as new form.


    but now, when form1 is loaded, and i want to close it thru the other form,
    Dim Form1 As Form1
    If ActiveLock1.RegisteredUser = False Then Form1.Close()

    I get
    Object reference not set to an instance of an object.


    ARGH!!!

    this is absolutely ridiculous - how can it be so hard to close a freaking form? i tried compiling it and i get piles and piles of errors - from when the app starts to when it ends. what the hell? just close the damn form already!

    5 hours ive spent now on simply transforming this vb code to vb.net
    VB Code:
    1. If Activelock1.RegisteredUser = True Then
    2. Form1.Show
    3. Unload Form2
    4. End if

    when i converted my vb6 app to .net, it said that to close a form, the code was Form1.DefInstance.Close(). Very good, so i went into my vb app, typed Form1. and guess what - NO DEFINSTANCE! It goes DefaultForeColor right to DesktopBounds.
    What in gods name is wrong with you vb.net!
    Last edited by VaxoP; Aug 2nd, 2003 at 04:08 PM.

  19. #19
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by VaxoP
    its not that easy..

    form1 is the main form - its the actual program. form2 is a check to see if the person has registered the program. in form2 theres a serial and a keycode textbox. if the combination is right, or the right data is retrieved from the registry, the person is registered.

    all im trying to do is close the register form if the person is registerd and open the main form.. but the register form refuses to leave
    If this is your problem, then you might show form2 as dialog, then if registration is ok return a dialogresult like OK and close form2 and in form1 continue, if not retrun another result and in form1 exit the application.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    Originally posted by Lunatic3
    If this is your problem, then you might show form2 as dialog, then if registration is ok return a dialogresult like OK and close form2 and in form1 continue, if not retrun another result and in form1 exit the application.
    gah?

  21. #21
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by VaxoP
    gah?
    Form1.ShowDialog()

  22. #22
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    this goes in form1 where you want to check for registration key
    VB Code:
    1. Dim frm as New From2
    2. If  If frm.ShowDialog = DialogResult.OK Then
    3.  ' Here continue with your program
    4. Else
    5.  ' Exit the Program
    6. End if
    And in form2 where you check the registration key
    VB Code:
    1. If 'user regsiteres' Then
    2. Me.dialogResult=OK
    3. Else
    4. Me.DialogResult=Cancel
    5. End If
    6. Me.Close
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  23. #23
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    okay had a similar task to do, what I did was to put a me.close in the form load base event, if I didn't need to show the form. Actually I used form2.showdialog not sure if that made a differerence, should not have - that certainly worked, if you need example working code, just ask.

  24. #24
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    ah follow up, I see you are upgrading from VB6, yes not as easy as microsoft tells you, we effectively redesigned and rewrote quite a lot of the application. ADO is too tempting as well, it's disconnected method of databsae access and the VB .Net full class based method of programming makes it very difficult not to undertake a redesign of your application. To me VB .Net has become a total head rethink in how we develop applications. I defy you not to resist the temptation to get into redesign!!!

  25. #25
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    oh and finally I used a shared member class to return the result rather than the method shown in your thread
    as in

    Public Class Result
    Public Shared Msg As String

    End Class

    and just set the message in the form I am in to be interrogated by the form I return to.

    Hope this all helps rather than confuses but spent may hours getting this way to work.

  26. #26
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I always heard people say that VB6 teaches bad programming habits I guess this is one of them. Or at least unless you got into class work then it doesn't help you learn the idea of instances. Also as a suggestion it is less confusing if you don't name your instance variable the same name as the type. So instead of:
    Dim Form1 As New Form1
    Try changing the instance variable name:
    Dim frm As New Form1

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