468,780 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

Getting a reference to the startup form?

I have a class called App set as the startup object with the following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to it
called FrmMain in my Sub Main? How else can I get a reference to the startup
form?

Regards,

Chris
Nov 21 '05 #1
4 3392
Chris,

I never use that classic startup method you show as something extra however
VB6 and C diehards like it.

Your mainform can in VBNet be the startup object it needs nothing more than
that you do not change the application settings and keep it with the name of
that form (class).

However there is nothing wrong with changing the name of that object and
than you have to change the startup object in the application properties.
(When you rename it, that goes not automaticly what you would suspect)

Solution explorere -> Application right click -> properties -> Startup
object and set the startup form.

I hope this helps?

Cor
Nov 21 '05 #2

"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> wrote in message
news:416ce78a.0@entanet...
I have a class called App set as the startup object with the following
code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to
it called FrmMain in my Sub Main? How else can I get a reference to the
startup form?

Regards,

Chris


I sorted this by using a shared property in my startup class. Here's the
code I'm using now:

Public Class App
Private Shared m_FrmMain As MainForm
Public Shared Property FrmMain() As MainForm
Get
Return m_FrmMain
End Get
Set(ByVal Value As MainForm)
m_FrmMain = Value
End Set
End Property
<STAThread()> _
Shared Sub Main()
Dim FrmStart As New MainForm
FrmMain = FrmStart
FrmMain.ShowDialog()
End Sub
End Class

Now I can access my main form through App.FrmMain - was this the right way
to do this?

Regards,

Chris
Nov 21 '05 #3
Hi,

You declared frmMain inside a subroutine. It is only available in
the subroutine.

Ken
--------------------
"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> wrote in message
news:416ce78a.0@entanet...
I have a class called App set as the startup object with the following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared. Didn't I get a reference to it
called FrmMain in my Sub Main? How else can I get a reference to the startup
form?

Regards,

Chris

Nov 21 '05 #4
"Chris Ashley" <ch**********@SPAMblueyonder.co.uk> schrieb:
I have a class called App set as the startup object with the
following code:

Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class

In another form I use the following code:

Private Sub AddCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FrmMain.Text = "Add Customer"
End Sub

I get the error that FrmMain is not declared.


Providing a reference to an application’s main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Zippy | last post: by
1 post views Thread by cefrancke | last post: by
4 posts views Thread by Tony Vitonis | last post: by
4 posts views Thread by Johnnie Miami | last post: by
10 posts views Thread by =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post: by
11 posts views Thread by Hotrod2000 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.