Exforsys.com
 
Home Tutorials VB.NET 2005
 

Application Class and Message Class

 

Application Class and Message Class

Page 1 of 2

Using Application Class

Visual Basic 2005 introduces a speedy way to access many important classes relating to the Computer on which the application is running, the user running it, the application itself, its forms and any associated web services. The best part of it all is that you can access it all using the new My object. The new My object has added features that help the programmer to gain access to some functionality that was really hard to achieve.



My.Application Object contains information about running application, such as the title, working directory, version, and the common language runtime (CLR) version in use. It also gives access to environment variables, allow you to easily write to the local application log or to a custom log, and so on.


You can access the Application information easily as can be seen in the following lines of code


My.Application.AssemblyInfo.DirectoryPath
My.Application.AssemblyInfo.ProductName
My.Application.Log.WriteEntry(“Application Starting”, EventLogEntryType.Information, Nothing)


The above lines of code will retrieve this information from the assembly which can used by the application on run time.


The following table gives the properties and methods of the My.Application Object


ApplicationContext Gives access to the context associated with the current thread.


AssmblyInfo Allows easy access to data from the AssemblyInfo.vb file, including CompanyName, ProductName, Title and Version.


ChangeCurrentCulture Allows Change the culture in which the current thread is running, which affects such things as string manipulation and formatting


ChangeCurrentUICulture Allows changing the culture that the current thread uses for retrieving culture-specific resources


CommandLineArgs Return a collection of command-line arguments


CurrentCulture Returns a collection of command-line arguments


CurrentDirectory Returns the folder where the application resides


CurrentUICulture Returns the culture that the current thread is using for retrieving culture-specific resources


DoEvents Causes all messages in the message queue to be processed


GetEnvironmentVariable Returns a specific environment variable on the local maching\e


IsNetWorkDeployed Returns True if the application was network-deployed else returns False.


Log Allows writing to application log on the local machine


MainForm A read-write property that allows setting or getting the form that the application will use as its main form


Run Sets up and starts the VB Startup/Shutdown Application model


SplashScreen Lets setting or getting the application's splash screen


Using the MessageBox class

Message boxes are often used objects. They are derived form Form Class, displayed modally and used to take user’s acknowledgement and also inform the user or alert the user of any thing that needs to be informed or alerted.



You cannot create a new instance of the System.Windows.Forms.MessageBox class. To display a message box, call the static method System.Windows.Forms.MessageBox.Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.


The following example shows how to use a System.Windows.Forms.MessageBox to inform the user of a missing entry in a System.Windows.Forms.TextBox.


This example assumes that the method is called from an existing form with a System.Windows.Forms.Button and a System.Windows.Forms.TextBox on it.


Protected Sub button1_Click(sender As Object, e As System.EventArgs)
If textBox1.Text = "" Then
MessageBox.Show("You must enter a name.", "Name Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
' Code to act on the data entered would go here.
End If
End Sub


Next Page: MessageBox class Parameters


Read Next: Setting and Adding Properties to Windows Form



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape