473,409 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

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 3882
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Zippy | last post by:
Some months ago, we requested help from this newsgroup on how to replace the library reference of a database with another library reference, prior to creating an MDE. I got the following answer...
5
by: mark s | last post by:
How can I make a checkbox that says "Do not show this again at startup" on my reminder form? Thanks! -- name: Mark S. email: huskie_009@hotmail.com *** Sent via Developersdex...
1
by: cefrancke | last post by:
I have set the Startup properties to the following... All menus, toolbars, etc are turned off plus these are unchecked Allow Full Menus Allow Built-in Toolbars Allow Default Shortcut Menus...
4
by: Tony Vitonis | last post by:
Hello. I've written an app that I want to "live" in the system tray. I want it to start up with just a tray icon showing, and if the user selects "Settings..." from the icon's context menu, to...
2
by: Mark D | last post by:
Hi Relative vb.net newbie here... I have a Windows Form application with a few subroutines in a separate module. From one of the subroutines, I want to get the value of a label or text box on...
4
by: Johnnie Miami | last post by:
I'm using VB.Net 2005 beta 2 and have my login form (login.vb) specified as the startup form. If the user is successful logging in, I call my main form (main.vb). This all works fine but the...
4
by: John Mishefske | last post by:
I have a "Tracker" class that registers "Messenger" classes to allow distribution of unicast and broadcast messages between instances. In code a reference to the Tracker class instance is...
10
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi In my app I have a SplashScreen, a login form and a main form. On launching the app, I'd like to show the SplashScreen while reading config files and attempting a database connection. I show...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.