|
-
Nov 10th, 2008, 06:20 PM
#1
Thread Starter
Lively Member
[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
-
Nov 10th, 2008, 06:26 PM
#2
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.
-
Nov 10th, 2008, 06:38 PM
#3
Thread Starter
Lively Member
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
-
Nov 10th, 2008, 06:48 PM
#4
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:
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:
If regForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
' The register form returned DialogResult.OK so just do what you normally do in the Load eventhandler here
Else
' The register form didnt return DialogResult.OK so we must assume something didnt go as it should, close the form.
Me.Close()
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.
-
Nov 10th, 2008, 06:51 PM
#5
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:
Shared Sub Main() Dim registered As Boolean 'Determine whether app is registered here. If Not registered Then Dim dialogue As New RegistrationDialogue registered = (dialogue.ShowDialog() = Windows.Forms.DialogResult.OK) dialogue.Dispose() End If If registered Then Application.Run(New Form1) End If 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.
-
Nov 10th, 2008, 07:21 PM
#6
Thread Starter
Lively Member
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
-
Nov 10th, 2008, 07:28 PM
#7
Re: [2003] Calling a form
 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.
 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.
-
Nov 10th, 2008, 07:34 PM
#8
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|