标签:
IT/科技窗体 |
下面的代码实现窗体Form1和Form2之间互相调用,Form1为主窗体。Form1上的按钮BtnShowFrm2的标题为“显示Form2”,Form2上的按钮BtnShowFrm1的标题为“显示Form1”。
1、Form1中的代码:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifPublic Class Form1 Class Form1
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Inherits System.Windows.Forms.Form
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '创建Form2的一个新的实例
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Dim Frm2 As New Form2()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Public Function Instance2() Function Instance2( ByVal frm As Form2)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Frm2 = frm
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif End Function
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Private Sub BtnShowFrm2_Click() Sub BtnShowFrm2_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) _
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Handles BtnShowFrm2.Click
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '以下语句保证在Form2以及其他窗体中访问Form1时,
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '都将得到Form1的同一个窗体实例。
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Frm2.Instance( Me)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Frm2.Show()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Me.Hide()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif End Sub
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gifEndClass
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gifEnd
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
2、Form2中的代码:
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifPublic Class Form2 Class Form2
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Inherits System.Windows.Forms.Form
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Dim frm1 As Form1
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '借助一个新增的Instance属性来生成窗体frm1的实例
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Public Function Instance() Function Instance( ByVal frm As Form1)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1 = frm
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif End Function
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Private Sub BtnShowFrm1_Click() Sub BtnShowFrm1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) _
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Handles BtnShowFrm1.Click
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif Me.Hide()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.Show()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif EndSub
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Private Sub Form2_Closed() Sub Form2_Closed( ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '如果Form2被关闭,则设置Form1的按钮BtnShowFrm2不可用。
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.BtnShowFrm2.Enabled = False
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.Show()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif EndSub
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gifEndClass
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Public
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Private
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.Show()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif End
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif Private
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif '如果Form2被关闭,则设置Form1的按钮BtnShowFrm2不可用。
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.BtnShowFrm2.Enabled
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif frm1.Show()
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif End
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gifEnd
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif