|
-
Aug 2nd, 2003, 01:21 PM
#1
Thread Starter
Frenzied Member
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.
-
Aug 2nd, 2003, 01:44 PM
#2
Close another form, use
However, if you want the user to be able to use it again within the life of the main application, use
To show another forum, you first must declare it like
Then just use
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.
-
Aug 2nd, 2003, 01:46 PM
#3
Thread Starter
Frenzied Member
thanks
-
Aug 2nd, 2003, 02:03 PM
#4
Thread Starter
Frenzied Member
Dim form2 As New Form2()
form2.Close()
it still keeps showing up tho
-
Aug 2nd, 2003, 02:06 PM
#5
Originally posted by VaxoP
Dim form2 As New Form2()
form2.Close()
it still keeps showing up tho
Uh? What keeps showing up?
-
Aug 2nd, 2003, 02:14 PM
#6
Thread Starter
Frenzied Member
VB Code:
Dim Form1 As New Form1()
Dim Form2 As New Form2()
If ActiveLock1.RegisteredUser = True Then
Form1.Show()
Form2.Close()
Else
Text1.Text = ActiveLock1.SoftwareCode
Me.Show()
Text2.Focus()
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)
-
Aug 2nd, 2003, 02:18 PM
#7
use form2.Hide() then, because if that's the startup object, the whole application will terminate
-
Aug 2nd, 2003, 02:25 PM
#8
Thread Starter
Frenzied Member
no luck
VB Code:
Dim Form1 As New Form1()
Dim Form2 As New Form2()
If ActiveLock1.RegisteredUser = True Then
Form1.Show()
Form1.Focus()
Form2.Hide()
Else
Text1.Text = ActiveLock1.SoftwareCode
Me.Show()
Text2.Focus()
End If
End Sub
it still is visible
-
Aug 2nd, 2003, 02:27 PM
#9
Thread Starter
Frenzied Member
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:
Dim form2 As New Form2()
form2.Hide()
form2.Visible = False
-
Aug 2nd, 2003, 02:32 PM
#10
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
-
Aug 2nd, 2003, 02:36 PM
#11
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2003, 02:39 PM
#12
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....
-
Aug 2nd, 2003, 02:42 PM
#13
Thread Starter
Frenzied Member
VB Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim form2 As New Form2()
form2.Hide()
form2.Visible = False
End Sub
why wont that do anything?
-
Aug 2nd, 2003, 02:49 PM
#14
I think you only need
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:
#Region " Windows Form Designer generated code "
Dim frmChild As New frmChild
Dim frmAbout As New frmAbout
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)
-
Aug 2nd, 2003, 03:07 PM
#15
Thread Starter
Frenzied Member
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.
-
Aug 2nd, 2003, 03:14 PM
#16
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...
-
Aug 2nd, 2003, 03:36 PM
#17
Thread Starter
Frenzied Member
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?
-
Aug 2nd, 2003, 03:53 PM
#18
Thread Starter
Frenzied Member
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:
If Activelock1.RegisteredUser = True Then
Form1.Show
Unload Form2
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.
-
Aug 2nd, 2003, 04:14 PM
#19
Frenzied Member
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
-
Aug 2nd, 2003, 04:17 PM
#20
Thread Starter
Frenzied Member
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?
-
Aug 2nd, 2003, 04:21 PM
#21
Originally posted by VaxoP
gah?
Form1.ShowDialog()
-
Aug 2nd, 2003, 04:27 PM
#22
Frenzied Member
this goes in form1 where you want to check for registration key
VB Code:
Dim frm as New From2
If If frm.ShowDialog = DialogResult.OK Then
' Here continue with your program
Else
' Exit the Program
End if
And in form2 where you check the registration key
VB Code:
If 'user regsiteres' Then
Me.dialogResult=OK
Else
Me.DialogResult=Cancel
End If
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
-
Aug 2nd, 2003, 05:49 PM
#23
Hyperactive Member
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.
-
Aug 2nd, 2003, 05:57 PM
#24
Hyperactive Member
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!!!
-
Aug 2nd, 2003, 06:02 PM
#25
Hyperactive Member
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.
-
Aug 2nd, 2003, 11:22 PM
#26
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|