OK. I have created a global variable gfrmMain. However, how do you access the
Sub/Function in frmMain. In the Load event of frmMain I gfrmMain=frmMain. I
have a Public Sub DispStatMsg in frmMain. This does not expose
gfrmMain.DispStatMsg. A reference to gfrmMain.DispStatMsg causes a compile
error and does not display the message. I had tried this & re-did it to check
Terry
Here is a complete (quick'n'dirty) sample. Most of it
is just generated by the wizard.
Set Sub Main or frmMain as the startup object.
Your original code could probably be fixed to work so
gfrmMain would be a shared member of the FormMain
class, but I am not sure it makes any sense to have a
shared member or function of a class that will only exist
in a single instance.
/JB
---Module1.vb ---
Module Module1
Public gfrmMain As frmMain
Public Sub DisplayStatusMessage(ByVal message As String)
If Not gfrmMain Is Nothing Then
gfrmMain.StatusBarPanel1.Text = message
End If
End Sub
Public Sub main()
Dim frm As New frmMain
Application.Run(frm)
End Sub
End Module
--- frmMain.vb ---
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
Friend WithEvents StatusBarPanel1 As
System.Windows.Forms.StatusBarPanel
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.StatusBar1 = New System.Windows.Forms.StatusBar
Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
CType(Me.StatusBarPanel1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point(0, 251)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Panels.AddRange(New
System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1})
Me.StatusBar1.ShowPanels = True
Me.StatusBar1.Size = New System.Drawing.Size(292, 22)
Me.StatusBar1.TabIndex = 0
Me.StatusBar1.Text = "StatusBar1"
'
'StatusBarPanel1
'
Me.StatusBarPanel1.AutoSize =
System.Windows.Forms.StatusBarPanelAutoSize.Spring
Me.StatusBarPanel1.Width = 276
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.StatusBar1)
Me.Name = "frmMain"
Me.Text = "frmMain"
CType(Me.StatusBarPanel1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
gfrmMain = Me
Dim frm2 As New Form2
frm2.Owner = Me
frm2.Show()
Dim frm3 As New Form3
frm3.Owner = Me
frm3.Show()
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'Note: I chose the _Closing event rather than the
' _Closed or _HandleDestroyed ones, as the
' form is still alive at _Closing time and
' the statusbar therefore still accessible.
gfrmMain = Nothing
End Sub
End Class
--- Form2.vb ---
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 24)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
DisplayStatusMessage("Message from Form2")
End Sub
End Class
--- Form3.vb ---
Public Class Form3
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 24)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form3
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form3"
Me.Text = "Form3"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
DisplayStatusMessage("Message from Form3")
End Sub
End Class