VB.NET 2005 Free Training
Exploring the Forms Designer generated code
As you create a new project in the Visual Basic, the IDE generally automatically adds lots of lines of code on its own. Visual Basic 2005 comes with an option to skip over this behavior of the Visual Basic IDE. The default option comes with this behavior enabled.
These codes are introduced with an aim that the user can continue to use the form without bothering about write codes to instantiate the form with a function new() and also the code includes the declaration and instantiation of all the controls that have been dragged and dropped on to the form. As a developer you may need to add controls like text boxes, grid controls, database controls and also need to bind data to some control at design time.
Much of these activities can be done at design time and visually without adding any line of code. The Visual Basic IDE is equipped with inbuilt facility that generates codes for these features. The more interesting part is not just that. You can actually add functionality to the form by adding codes to these functions like new() which is the first function to be executed and can be used to perform additional tasks at the start time of the application or even before the form load takes place.
This code is stored in a new file Form1.Designer.vb. Let us take a closer look at this now. These codes that we are going to see have been taken from one of the demos of this tutorial.
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() > _
Partial Public Class Form1
‘Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
‘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.
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button1.Location = New System.Drawing.Point(13, 238)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Line"
Me.Button2.Location = New System.Drawing.Point(98, 238)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Ellipse"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(612, 273)
Me.Name = "Form1"
Me.Text = "Painting Shapes and Fill Objects"
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
InitializeComponent: This method helps to persist the property values that you have set in the Designer.
Public Sub New():The class constructor. You can put include some code that you want at the start up. However the best location for this code is the forms Load event.
Security in Windows Form:
The .NET Framework provides a superior security features in the application by introducing new features. The code access security allows you to permit varied degrees or trust to the code depending on where the code originates and also other factors that define the identity of the code. Security permissions are implemented to ensure security. Code can request the permissions it needs.
The .NET Framework security system determines whether such requests are honored. Requests are honored after verifying the code’s evidence and only relevant requests are granted those permissions. The permission given to the code never exceeds the current security settings. However, code will be granted less permission based upon a request.
The identity of the code forms the basis for granting the runtime permissions, also the level of trust the code is granted is determined by the security policy.
Code can demand that its callers have specific permissions. If you place a demand for certain permission on your code, all code that uses your code must have that permission to run.
There are three kinds of permissions, each with a specific purpose
Code access permissions, which represent access to a protected resource or the ability to perform a protected operation.
Identity permissions, which indicate that code has credentials that support a particular kind of identity.
Role-based security permissions, which provide a mechanism for discovering whether a user has a particular identity or is a member of a specified role. Thus a very robust and well managed security is provided in the .NET Framework.