Results 1 to 8 of 8

Thread: [RESOLVED] [2003] Calling a form

  1. #1

    Thread Starter
    Lively Member therat324's Avatar
    Join Date
    Oct 2008
    Location
    Bethany, Oklahoma
    Posts
    94

    Resolved [RESOLVED] [2003] Calling a form

    I just finished the program im working on. Now im working on making an opening screen that pops up before the main program can run.

    I created the register form after the main program. I need to find a way to have the main program check to see if its been registered (by looking for a file it creates on setup). If it is still in trial version, the main program needs to open up the register window BEFORE it loads anything.

    So...

    User clicks "main program"

    Before main form loads everything(buttons, labels ...ect) it opens the register form. so all the user can do is interact with the register form. If they enter the key it will load the main form fully. If the user does not enter a register key the register form closes and so does the main form.

    Make sence?

    I need to know how to make the main form show the register form, without letting any of the main form be used.
    My car if Chevy was VB.NET

    Code:
    Public Class MyCar
        Public Sub Camaro()
            Dim Camaro As Car
            Camaro = SS.Fast("Sexy")
        End Sub
    
        Public Function Fast(ByVal sexy As String ) As String
            Return "SUPER" & sexy
        End Function
    End Class

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2003] Calling a form

    In the Main forms Load eventhandler, create and show the Register form using the ShowDialog method, handle its return value to determine wether the Main form should continue loading, or close itself.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Lively Member therat324's Avatar
    Join Date
    Oct 2008
    Location
    Bethany, Oklahoma
    Posts
    94

    Re: [2003] Calling a form

    Im still kind of new to VB so...

    the register form is register.vb

    so would my code look like this?

    Code:
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
    showdialog(register)
    
    ....
    end class
    My car if Chevy was VB.NET

    Code:
    Public Class MyCar
        Public Sub Camaro()
            Dim Camaro As Car
            Camaro = SS.Fast("Sexy")
        End Sub
    
        Public Function Fast(ByVal sexy As String ) As String
            Return "SUPER" & sexy
        End Function
    End Class

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2003] Calling a form

    The filename (register.vb) doesnt make any difference, what is important is the name of the class you've defined in the file. I'm going to go ahead and assume its called "Register"

    You'd have to create a new instance of it first:
    VB.NET Code:
    1. Dim regForm As New Register()
    And then call its ShowDialog method. The ShowDialog method returns a DialogResult value that you'd need to use in order to know if you should close the main form or not. So here's how you'd do:
    VB.NET Code:
    1. If regForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
    2.     ' The register form returned DialogResult.OK so just do what you normally do in the Load eventhandler here
    3. Else
    4.     ' The register form didnt return DialogResult.OK so we must assume something didnt go as it should, close the form.
    5.     Me.Close()
    6. End If

    Now in the Register form, when the user has performed the action that allows it to continue using the program, set its DialogResult property to Windows.Forms.DialogResult.OK, and otherwise, just close the form.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] Calling a form

    If you don't need a main form then don't create one at all. There's no point opening it and then closing it again. You should start your app from a Main method. Add something like this to your main form:
    vb.net Code:
    1. Shared Sub Main()
    2.     Dim registered As Boolean
    3.  
    4.     'Determine whether app is registered here.
    5.  
    6.     If Not registered Then
    7.         Dim dialogue As New RegistrationDialogue
    8.  
    9.         registered = (dialogue.ShowDialog() = Windows.Forms.DialogResult.OK)
    10.         dialogue.Dispose()
    11.     End If
    12.  
    13.     If registered Then
    14.         Application.Run(New Form1)
    15.     End If
    16. End Sub
    That Main method will now be used as the entry point for your app. You first look for the file to determine whether the app is already registered. I'll leave that up to you. If it's not then you display a registration dialogue. It returns OK if registration is successful and Cancel if it's not. After that, if the app is registered then a main form is opened. If the app isn't registered then it just exits without ever creating a main form.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Lively Member therat324's Avatar
    Join Date
    Oct 2008
    Location
    Bethany, Oklahoma
    Posts
    94

    Re: [2003] Calling a form

    So how would i make main the entry point for my program? and how do i get my register form to return dialogresult.ok?

    It has 2 buttons on it
    ExitBTN
    RegisterBTN

    exit closes program
    RegisterBTN will look in the textbox and verify if the key is valid.
    If so is this how i should make it return ok to dialogresult
    Code:
    DialogResult = DialogResult.OK
    Last edited by therat324; Nov 10th, 2008 at 07:27 PM.
    My car if Chevy was VB.NET

    Code:
    Public Class MyCar
        Public Sub Camaro()
            Dim Camaro As Car
            Camaro = SS.Fast("Sexy")
        End Sub
    
        Public Function Fast(ByVal sexy As String ) As String
            Return "SUPER" & sexy
        End Function
    End Class

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2003] Calling a form

    Quote Originally Posted by therat324
    So how would i make main the entry point for my program?
    If memory serves me then, if you followed my instructions, you don't have to do anything. If you specify a form that contains a Main method as your startup object then the Main method will be used as the entry point automatically. If that's not correct (and my memory is failing ) then you will need to go to the project properties and select Sub Main as your startup object.
    Quote Originally Posted by therat324
    how do i get my register form to return dialogresult.ok?
    To dismiss a form that has been displayed by calling its ShowDialog method you simply set its DialogResult property to any value other than None. The form will be dismissed and ShowDialog will return that value. In your registration form you will set Me.DialogResult to either Windows.Forms.DialogResult.OK or
    Windows.Forms.DialogResult.Cancel.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member therat324's Avatar
    Join Date
    Oct 2008
    Location
    Bethany, Oklahoma
    Posts
    94

    Re: [2003] Calling a form

    ok thank you guys. Works good now :-D
    My car if Chevy was VB.NET

    Code:
    Public Class MyCar
        Public Sub Camaro()
            Dim Camaro As Car
            Camaro = SS.Fast("Sexy")
        End Sub
    
        Public Function Fast(ByVal sexy As String ) As String
            Return "SUPER" & sexy
        End Function
    End Class

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