這是由于你的啟動類是form1,也就是說form1是你的主函數(shù),你關(guān)閉form1就相當于關(guān)閉程序;
創(chuàng)新互聯(lián)成立于2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目做網(wǎng)站、成都網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元黃島做網(wǎng)站,已為上家服務(wù),為黃島各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
如果你只希望彈出form2的時候form1隱藏,可以再form2.show()之后調(diào)用form1.hide(),之后關(guān)閉form2的時候再關(guān)閉form1就可以達到你想要的效果了;
再有一種做法就是你需要一個主函數(shù)類,使用它調(diào)用form1跟form2,這樣關(guān)閉哪一個都不會影響另一個。
頂你啊
窗體的
MaxButton
屬性設(shè)為False
不就沒最大化了
或者設(shè)置
BorderStyle屬性
===================================
Private
Declare
Function
GetSystemMenu
Lib
"user32"
(ByVal
hwnd
As
Long,
ByVal
bRevert
As
Long)
As
Long
Private
Declare
Function
RemoveMenu
Lib
"user32"
(ByVal
hMenu
As
Long,
ByVal
nPosition
As
Long,
ByVal
wFlags
As
Long)
As
Long
Private
Const
MF_REMOVE
=
H1000
Private
Const
SC_CLOSE
=
HF060
Sub
Disabled(ChWnd
As
Long)
'設(shè)置窗體關(guān)閉按鈕不可用的子過程
Dim
hMenu,
hendMenu
As
Long
Dim
c
As
Long
hMenu
=
GetSystemMenu(ChWnd,
0)
RemoveMenu
hMenu,
SC_CLOSE,
MF_REMOVE
End
Sub
Private
Sub
Form_Load()
Disabled
Me.hwnd
'調(diào)用子過程
End
Sub
this.close() 只是關(guān)掉,沒有釋放,不對 me.close() 應(yīng)該釋放一下 me.Dispose() 給分吧、
Private Sub frmNotepad_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Call subexit()
End
End Sub
Sub subexit()
Dim frmNew As frmNotepad
frmNew = ActiveForm
If frmNew.Text = "未定標題 - 記事本" Then
If frmNew.rtb.Text = "" Then
Else
Dim result As New MsgBoxResult 'result提示對話框yes,no,cancel
result = MsgBox("未定標題 文件的文字已經(jīng)改變。" Chr(10) Chr(10) "想保存文件嗎?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Exclamation, "記事本")
If result = MsgBoxResult.Yes Then 'result.Yes表示保存,清空內(nèi)容,打開新頁面
Dim fileSave As New SaveFileDialog
Dim re As New DialogResult 're提示對話框OK,cancel
fileSave.FileName = "*.txt"
fileSave.Filter = "文本文檔(*.txt)|*.txt|所有文件|*.*"
re = fileSave.ShowDialog()
If re = DialogResult.OK Then 're.OK表示成功保存,清空內(nèi)容,打開新頁面
filename = fileSave.FileName
Dim fstream As FileStream
Dim sw As StreamWriter
Try
'frmNew.Text = filename.Substring(filename.LastIndexOf("\") + 1) "- 記事本"
fstream = New FileStream(filename, FileMode.Create, FileAccess.ReadWrite)
sw = New StreamWriter(fstream, System.Text.Encoding.Default)
sw.BaseStream.Seek(0, SeekOrigin.End)
sw.Write(rtb.Text)
sw.Flush()
Catch ex As Exception
MsgBox("保存文件失敗")
Finally
sw.Close()
End Try
ElseIf re = DialogResult.Cancel Then 're.cancel表示不保存,不改變?nèi)魏谓Y(jié)果
End If
ElseIf result = MsgBoxResult.No Then 'result.no表示不保存,清空內(nèi)容
rtb.Text = ""
End If
End If
Else
If rtb.Text.Compare(rtb.Text, compareStr) 0 Then
Dim result As New MsgBoxResult
result = MsgBox(filename + " 文件的文字已經(jīng)改變。" Chr(10) Chr(10) "想保存文件嗎?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Exclamation, "記事本")
If result = MsgBoxResult.Yes Then
Dim fstream As FileStream
Dim sw As StreamWriter
Try
'frmNew.Text = filename.Substring(filename.LastIndexOf("\") + 1) "- 記事本"
fstream = New FileStream(filename, FileMode.Create, FileAccess.ReadWrite)
sw = New StreamWriter(fstream, System.Text.Encoding.Default)
sw.BaseStream.Seek(0, SeekOrigin.End)
sw.Write(rtb.Text)
sw.Flush()
Catch ex As Exception
MsgBox("保存文件失敗")
Finally
sw.Close()
End Try
ElseIf result = MsgBoxResult.No Then
rtb.Text = ""
End If
End If
End If
End Sub
首先這個應(yīng)該放在 FormClosing 事件中。
其次,因為你 Else 之后沒有忽略窗體關(guān)閉的請求。
應(yīng)該再加一句 e.Cancel = True,表示告訴系統(tǒng),我取消關(guān)閉窗體這個操作了。
如果這個窗體是主窗體的話,你只能隱藏,因為主窗體關(guān)閉的話程序就退出了。
如果不是主窗體,可以用Form1.Close來關(guān)閉。
如果實在是想關(guān)閉,就得把程序啟動設(shè)為sub
main而不是form。
再由sub
main來啟動窗體,這樣就沒有主窗體了。
分享題目:vb.net窗體關(guān)閉不了 vb窗口不見了
分享網(wǎng)址:http://jinyejixie.com/article16/hepcdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、軟件開發(fā)、企業(yè)網(wǎng)站制作、手機網(wǎng)站建設(shè)、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)