how can you close another form?
or show another form?
Please see my last post in this thread..
Printable View
how can you close another form?
or show another form?
Please see my last post in this thread..
Close another form, use
However, if you want the user to be able to use it again within the life of the main application, useVB Code:
Form1.Close()
VB Code:
Form1.Hide()
To show another forum, you first must declare it like
VB Code:
Dim Form1 As New Form1
Then just use
VB Code:
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.
:)
thanks :)
Dim form2 As New Form2()
form2.Close()
it still keeps showing up tho :(
Uh? What keeps showing up?Quote:
Originally posted by VaxoP
Dim form2 As New Form2()
form2.Close()
it still keeps showing up tho :(
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)
use form2.Hide() then, because if that's the startup object, the whole application will terminate
no luck
it still is visibleVB 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
now i added a button and clicked it to try and close the damn thing thru form1 - but still it has no effect on itVB Code:
Dim form2 As New Form2() form2.Hide() form2.Visible = False
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
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
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....
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?
I think you only need
VB Code:
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:
#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)
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...Quote:
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.
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?
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!
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.Quote:
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
gah?Quote:
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.
Form1.ShowDialog()Quote:
Originally posted by VaxoP
gah?
this goes in form1 where you want to check for registration keyAnd in form2 where you check the registration keyVB Code:
Dim frm as New From2 If If frm.ShowDialog = DialogResult.OK Then ' Here continue with your program Else ' Exit the Program End if
VB Code:
If 'user regsiteres' Then Me.dialogResult=OK Else Me.DialogResult=Cancel End If Me.Close
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.
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!!!
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.
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