|
-
Mar 22nd, 2002, 06:36 AM
#1
Thread Starter
Lively Member
Unloading a Form
I'm looking for the equivalent of the unload.form2 command in VB.NET and what event that needs to be placed in.
In VB6:
Click button1 on form 1 event: form2.show:form1.hide
Click button1 on form 2 event: form1.show:form2.hide
and in my form1.unload I would have Unload.Form2:Unload.Me
Now I've got the showing/hiding of the forms OK with VB.NET, I use (in a module):
Public MainForm As New Form1()
Public ProgressForm As New Form2()
I can show/hide with mainform.hide/progressform.show e.t.c. all works fine but I know the progressform (form2) is not unloading when I quite the app from form1.
I've looked at the 'closing' and 'closed' events of form1 and added a progressform.dispose but no good as when I quit the app the VB.NET IDE has not stopped.
Anyone?
-
Mar 23rd, 2002, 07:51 AM
#2
Thread Starter
Lively Member
No one?
Is this VB.NET going from bad to worse?
All I want is the equivelent of: unload form2
-
Mar 23rd, 2002, 11:51 AM
#3
PowerPoster
I haven't gotten to reading up on the Windows Forms yet, but maybe try:
-
Mar 24th, 2002, 08:40 AM
#4
Thread Starter
Lively Member
Hi, thanks for the reply.
I've tried both formname.dispose and formname.close, neither worked .... or maybe I'm just putting them in the incorrect event???, I don't know. I'm putting them in the main forms closing, closed and leave, still nothing. :-(
-
Mar 24th, 2002, 10:48 AM
#5
Addicted Member
don't know but
try
Unload FormName
or
MyBase.Dispose
and if the fails use the DestroyWindow API
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 24th, 2002, 08:15 PM
#6
Thread Starter
Lively Member
-
Mar 24th, 2002, 10:43 PM
#7
New Member
Use Me.Dispose (True)
It works for me 
EDIT:
And if you know the name of the form then use Form1.ActiveForm.Dispose()
Assuming the name of the form is Form1
Last edited by Axyun; Mar 24th, 2002 at 10:46 PM.
-
Mar 24th, 2002, 11:49 PM
#8
Addicted Member
Tested & Works
-_-
Code:
frm.Dispose() 'Works
i used here in a note pade i am working on
look at:
Private Sub mnuFileOpen_Clicked
Private Sub mnuFileSave_Clicked
Code:
Option Explicit On
Option Strict On
Option Compare Binary
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Namespace VBNotepad
Public Class frmPad
Inherits System.Windows.Forms.Form
Private frm As New System.Windows.Forms.Form
Private WithEvents CodePane As System.Windows.Forms.TextBox
Private FileName as String = "New Source.vb"
Private FilePath as String = "C:\"
Private isChanged as Boolean = False
Private AlreadyExists As Boolean = False
<STAThread()> Shared Sub Main()
System.Windows.Forms.Application.Run(New frmPad())
End Sub
Public Sub New()
'
MyBase.New()
Call AddMenus()
Call AddCodePane()
Me.Text = "VB.Net Simple Code Pad"
Me.TopMost = True
End Sub
Overrides Protected Sub OnResize(ByVal e As EventArgs )
CodePane.Size = New Size(Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
End Sub
'Menu Creation and Event Handlers
'***********************************************************************************************
Private Sub AddMenus()
Dim mnuMain As New MainMenu
Dim mnuFile As MenuItem = mnuMain.MenuItems.Add("&File")
'File Menu
mnuFile.MenuItems.Add("&New", New EventHandler(AddressOf Me.mnuFileNew_Clicked))
mnuFile.MenuItems.Add("&Open", New EventHandler(AddressOf Me.mnuFileOpen_Clicked))
mnuFile.MenuItems.Add("&Save", New EventHandler(AddressOf Me.mnuFileSave_Clicked))
mnuFile.MenuItems.Add("Save Copy",New EventHandler(AddressOf Me.mnuFileSaveCopy_Clicked))
mnuFile.MenuItems.Add("-") 'Seperator
mnuFile.MenuItems.Add("Build", New EventHandler(AddressOf Me.mnuFileBuild_Clicked))
mnuFile.MenuItems.Add("-")
mnuFile.MenuItems.Add("E&xit", New EventHandler(AddressOf Me.mnuFileExit_Clicked))
Me.Menu = mnuMain
End Sub
Private Sub mnuFileNew_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
If isChanged = True Then
Call SaveFile()
End If
CodePane.Text = ""
End Sub
Private Sub mnuFileOpen_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
frm.Show
End Sub
Private Sub mnuFileSave_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
frm.Dispose
End Sub
Private Sub mnuFileSaveCopy_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
Private Sub mnuFileBuild_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
Private Sub mnuFileExit_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
'***********************************************************************************************
'CodePane Creation and Event Handlers
'***********************************************************************************************
Private Sub AddCodePane()
'
Me.CodePane = New System.Windows.Forms.TextBox
CodePane.Location = New Point(1, 1)
CodePane.TabIndex = 2
CodePane.Size = New Size(Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
CodePane.Multiline = True
CodePane.AcceptsReturn = True
CodePane.AcceptsTab = True
CodePane.WordWrap = False
CodePane.Scrollbars = ScrollBars.Both
AddHandler CodePane.TextChanged, AddressOf Me.CodePane_TextChanged
Me.Controls.Add(CodePane)
End Sub
Private Sub CodePane_TextChanged(sender As Object, e As EventArgs)
'
isChanged = True
End Sub
'************************************************************************************************
'General Methods
'************************************************************************************************
Private Sub SaveFile()
End Sub
'*************************************************************************************************
End Class
End Namespace
to compile save as vbNote.vb and put
Code:
vbc.exe vbNote.vb /r:System.dll /r:System.Drawing.dll /r:System.Windows.Forms.dll /target:winexe /out:vbNote /bugreport:vbNoteError.log
in a batch file @ the same path then dblClick
Last edited by ZanM; Mar 25th, 2002 at 12:35 AM.
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 25th, 2002, 01:47 AM
#9
Lively Member
There you go again...
There you go again with the complex chit again
Hey Zan I'm telling you all these folks are Newbies
Hey WideAwake if you want to tried and true easy method:
Code:
Option Explicit On
Option Strict On
Option Compare Binary
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Namespace TestDispose
#Region
Public Class frmDispose
Inherits System.Windows.Forms.Form
Private frm As New System.Windows.Forms.Form
Private isLoaded As Boolean = False
<STAThread()> Shared Sub Main()
System.Windows.Forms.Application.Run(New frmDispose())
End Sub
Public Sub New()
MyBase.New()
Call AddMenus()
Me.Text = "VB.Net Dispose Test"
Me.TopMost = True
End Sub
End Region
'Menu Creation and Event Handlers
'***********************************************************************************************
Private Sub AddMenus()
Dim mnuMain As New MainMenu
Dim mnuFile As MenuItem = mnuMain.MenuItems.Add("&File")
mnuFile.MenuItems.Add("&Exit",New EventHandler(AddressOf Me.FormDispoer))
Me.Menu = mnuMain
End Sub
Private Sub FormDispoer(sender As Object, e As System.EventArgs)
Me.Dispose
End Sub
'***********************************************************************************************
End Class
End Namespace
This one works to
Copy this into your batch file
Code:
vbc.exe frmDipose.vb /r:System.dll /r:System.Drawing.dll /r:System.Windows.Forms.dll /target:winexe /out:"Unload Form.exe" /bugreport:err.log
There is no good or evil only CODE! ~MedevH~
-
Mar 25th, 2002, 03:59 AM
#10
Thread Starter
Lively Member
But when you try to show the form for the 2nd time you get an error saying 'Cannot access disposed form'.
-
Mar 25th, 2002, 09:21 AM
#11
Lively Member
HERE!!!!
I fixed that problem for you
but your gonna have to weed it out yourself
that way you'll learn from it
by the way you said dispose didn't work
not that Zan's program didn't have a bug in
I recommend downloading the .NET SDK
and if you have then USE IT!!!!
Code:
Option Explicit On
Option Strict On
Option Compare Binary
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Namespace VBNotepad
Public Class frmPad
Inherits System.Windows.Forms.Form
Private frm As System.Windows.Forms.Form
Private WithEvents CodePane As System.Windows.Forms.TextBox
Private FileName as String = "New Source.vb"
Private FilePath as String = "C:\"
Private isChanged as Boolean = False
Private AlreadyExists As Boolean = False
<STAThread()> Shared Sub Main()
System.Windows.Forms.Application.Run(New frmPad())
End Sub
Public Sub New()
'
MyBase.New()
Call AddMenus()
Call AddCodePane()
Me.Text = "VB.Net Simple Code Pad"
Me.TopMost = True
End Sub
Overrides Protected Sub OnResize(ByVal e As EventArgs )
CodePane.Size = New Size(Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
End Sub
'Menu Creation and Event Handlers
'***********************************************************************************************
Private Sub AddMenus()
Dim mnuMain As New MainMenu
Dim mnuFile As MenuItem = mnuMain.MenuItems.Add("&File")
'File Menu
mnuFile.MenuItems.Add("&New", New EventHandler(AddressOf Me.mnuFileNew_Clicked))
mnuFile.MenuItems.Add("&Open", New EventHandler(AddressOf Me.mnuFileOpen_Clicked))
mnuFile.MenuItems.Add("&Save", New EventHandler(AddressOf Me.mnuFileSave_Clicked))
mnuFile.MenuItems.Add("Save Copy",New EventHandler(AddressOf Me.mnuFileSaveCopy_Clicked))
mnuFile.MenuItems.Add("-") 'Seperator
mnuFile.MenuItems.Add("Build", New EventHandler(AddressOf Me.mnuFileBuild_Clicked))
mnuFile.MenuItems.Add("-")
mnuFile.MenuItems.Add("E&xit", New EventHandler(AddressOf Me.mnuFileExit_Clicked))
Me.Menu = mnuMain
End Sub
Private Sub mnuFileNew_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
If isChanged = True Then
Call SaveFile()
End If
CodePane.Text = ""
End Sub
Private Sub mnuFileOpen_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
Set frm = New System.Windows.Forms.Form
frm.Show
End Sub
Private Sub mnuFileSave_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
frm.Dispose
End Sub
Private Sub mnuFileSaveCopy_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
Private Sub mnuFileBuild_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
Private Sub mnuFileExit_Clicked(ByVal sender as Object, ByVal e As System.EventArgs)
'
End Sub
'***********************************************************************************************
'CodePane Creation and Event Handlers
'***********************************************************************************************
Private Sub AddCodePane()
'
Me.CodePane = New System.Windows.Forms.TextBox
CodePane.Location = New Point(1, 1)
CodePane.TabIndex = 2
CodePane.Size = New Size(Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
CodePane.Multiline = True
CodePane.AcceptsReturn = True
CodePane.AcceptsTab = True
CodePane.WordWrap = False
CodePane.Scrollbars = ScrollBars.Both
AddHandler CodePane.TextChanged, AddressOf Me.CodePane_TextChanged
Me.Controls.Add(CodePane)
End Sub
Private Sub CodePane_TextChanged(sender As Object, e As EventArgs)
'
isChanged = True
End Sub
'************************************************************************************************
'General Methods
'************************************************************************************************
Private Sub SaveFile()
End Sub
'*************************************************************************************************
End Class
End Namespace
There is no good or evil only CODE! ~MedevH~
-
Mar 25th, 2002, 09:35 AM
#12
Addicted Member
umm....
would you try to use a form in vb6 after you unloaded it? i mean you caould load a new one and use it but isn't that what you have to do in .net too..? MS is just hiding less of the C backbone from us now personally i like it the power of VB has trippled or more 0_0
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 25th, 2002, 12:38 PM
#13
Lively Member
You bet your arse Zan
The whole .NET framework has finally revealed Microsoft has an intelligent person working on thier staff.
There is no good or evil only CODE! ~MedevH~
-
Mar 26th, 2002, 05:02 PM
#14
Thread Starter
Lively Member
Why is everyone making controls at runtime ?
-
Mar 26th, 2002, 08:51 PM
#15
Addicted Member
well
i happen to be useing notepad and the framework to code in no IDE just me my brain and the compiler
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 26th, 2002, 08:53 PM
#16
Lively Member
There is no good or evil only CODE! ~MedevH~
-
Mar 26th, 2002, 09:46 PM
#17
Frenzied Member
Originally posted by WideAwake
Why is everyone making controls at runtime ?
Better question is why there's so much unrelated coding to such a [seemingly] simple question.
-
Mar 27th, 2002, 03:21 PM
#18
Lively Member
Only way newbies learn anything is by DOING IT!!!
all the extra code is to help him learn
3 ways of doing thing
right way
wrong way
easy way
I always prefer #1
There is no good or evil only CODE! ~MedevH~
-
Mar 27th, 2002, 05:22 PM
#19
Addicted Member
well because
I didn't feel like making a new app in notepad when i had the one i was working on and tested the dispose in already coded. I mean I did tell WideAwake axactly where to look in the cade and incase you can't tell MedevH used my code to make a simpler example. I got to say this thing is pretty sad it's been viewed over 100 times and any newbie should know how to do it. it's simple.
Code:
Dim frm as System.Windows.Forms.Form
Sub LoadForm()
Set frm = New System.Windows.Forms.Form
frm.Text = "New Form"
frm.Show
End Sub
Sub DisposeForm()
frm.Dispose()
End Sub
now let's just suppose you have a file called frmMp3Played.vb with the class frmMP3 that is compiled into you exe just change System.Windows.Forms.Form to be frmMP3 now you have a form that can be loaded and disposed of more than one time now if you want to keep the forms state just hide the form instead of disposeing of it.
is that better for you guys shessh i think maybe you need to try to make an app in notepad WideAwake then go on to vs.net because my code looks just like the designer makes if you look close or open the .vb file in notepad i just don't have vs.net
Magiaus
Visual Basic 6.0 SP5
Visual C++ 6.0 SP5
The only sovereign you can allow to rule you is reason.
-
Mar 29th, 2002, 06:15 PM
#20
Thread Starter
Lively Member
'MedevH' - "Only way newbies learn anything is by DOING IT!!!"
What a stupid statement, I'm new to VB.NET not VB in general. You seem more interested in showing people how to right vb.net code via notepad using the .NET SDK, which has nothing to do with the initial question. The amount of people I see ask questions to have a completely different question answered is quite remarkable.
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
|