Example 65 The HTML sent to the browser from the Hello Browser application

< DOCTYPE HTML PUBLIC - W3C DTD HTML 4.0 Transitional EN> < HTML> < HEAD> < title> Programing Visual Basic .NET< title> < meta name GENERATOR content Microsoft Visual Studio .NET 7.0> < meta name CODE_LANGUAGE content Visual Basic 7.0> < meta name vs defaultClientScript content JavaScript> < meta name vs targetSchema < body < form name Form1 method post action HelloBrowser.aspx id Form1> < input type hidden name _ _VIEWSTATE > < span id Label1...

Example 57 Clipping the area of a control

' Assumes Imports System.Drawing.Drawing2D Public Class MyControl Inherits UserControl Private Function CreateRegion( ) As Region Dim gp As New GraphicsPath( ) gp.AddEllipse(Me.ClientRectangle) Dim rgn As New Region(gp) Return rgn End Function Protected Overrides Sub OnResize(ByVal e As EventArgs) Me.Region Me.CreateRegion( ) End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) e.Graphics.FillEllipse(New SolidBrush(Me.ForeColor), Me.ClientRectangle) End Sub The CreateRegion method...

Example 82 Allowing an Sql DataAdapter object to infer Sql Update Insert and Delete statements from a Select statement

Dim strConnection As String Data Source localhost Initial Catalog Northwind amp Integrated Security True Dim cn As SqlConnection New SqlConnection strConnection cn.Open ' Create a data adapter object and set its SELECT command. Dim strSelect As String SELECT FROM Categories Dim da As SqlDataAdapter New SqlDataAdapter strSelect, cn ' Set the data adapter object's UPDATE, INSERT, and DELETE ' commands. Use the SqlCommandBuilder class's ability to auto' generate these...

The Printer Settings Class

The PrinterSettings class holds values that describe the capabilities and settings of a specific printer. It exposes these properties Indicates whether the printer can print on both sides of the paper. The syntax of the CanDuplex property is Public ReadOnly Property CanDuplex As Boolean Indicates whether the document being printed will be collated. The syntax of the Collate property is Public Property Collate As Boolean Indicates the number of copies to print. The syntax of the Copies property...

Detecting MDI Child Window Activation

Code in the MDI parent form class can be notified when an MDI child form becomes active inside an MDI parent form. Active means that the child form receives the input focus after another MDI child form or the MDI parent form had the input focus. To receive such notification, the MDI parent form must override the OnMdiChildActivate method defined in the Form class . For example ' Place this within the class definition of the MDI parent form. Protected Overrides Sub OnMdiChildActivate ByVal e As...

Handling Page Events

The base Page class may at times raise events. These events can be handled by the derived Page class the code-behind class or by code embedded in the web page. Although it's possible to define an event-handler subroutine, the preferred response to events raised by the Page class is to override the protected methods provided by the Page class. For example, the following method could be placed in the code-behind class, providing a way to respond to the loading of the page Protected Overrides Sub...

Example 622 The HTML view generated by Visual Studio NET when a custom control is added to a web form

lt Page Language vb AutoEventWireup false lt Register TagPrefix cc1 Namespace OReilly.VBNET Assembly HelloWebControl gt lt DOCTYPE HTML PUBLIC - W3C DTD HTML 4.0 Transitional EN gt lt HTML gt lt meta name GENERATOR content Microsoft Visual Studio .NET 7.0 gt lt meta name CODE_LANGUAGE content Visual Basic 7.0 gt lt meta name vs defaultClientScript content JavaScript gt lt meta name vs targetSchema lt HEAD gt lt body lt form id Forml method post runat server gt lt cc1 HelloWebControl id...

The Image List Class

The ImageList class allows you to manage a collection of images. The most important property of this class is Images, which returns an ImageList.ImageCollection object. The ImageList.ImageCollection class has methods to add and remove images from the collection. The Add method of the ImageList.ImageCollection class adds a bitmap image or an icon to the ImageList's image collection. The Add method has three overloads, whose signatures are given as follows Overloads Public Sub Add ByVal value As...

The List BoxObject Collection Class

This class represents all the items in a ListBox object. It has a Count property that returns the number of items in the ListBox and an Item property that returns the item object in a certain index position. The following sample code reiterates all the items in a ListBox control named listBox1 Dim items As ListBox.ObjectCollection In addition, the ListBox.ObjectCollection class has the following methods Add Adds an item to the ListBox object. Its syntax is where item is data of type Object that...

Connecting to a SQL Server Database

To read and write information to and from a SQL Server database, it is necessary first to establish a connection to the database. This is done with the SqlConnection object, found in the System.Data.SqlClient namespace. Here's an example ' Open a database connection. Dim strConnection As String Data Source localhost Initial Catalog Northwind amp Integrated Security True Dim cn As SqlConnection New SqlConnection strConnection cn.Open This code fragment instantiates an object of type...

The Web Method Attribute

The WebMethod attribute that is, the WebMethodAttribute class, defined in the System.Web.Services namespace identifies a method as being a web method. When the ASP.NET framework finds this method in a class being used as a web service, it wires up the plumbing necessary to expose the method as part of the web service. The properties that can be set for the WebMethod attribute are Specifies whether to buffer the response to the client while it is being built. The type is Boolean. The default is...

Relations Between Data Tables in a Data Set

The DataSet class provides a mechanism for specifying relations between tables in a DataSet. The DataSet class's Relations property contains a RelationsCollection object, which maintains a collection of DataRelation objects. Each DataRelation object represents a parent child relationship between two tables in the DataSet. For example, there is conceptually a parent child relationship between a Customers table and an Orders table, because each order must belong to some customer. Modeling this...

Example 61 The Web Forms Designers boilerplate HTML for a blank web form

lt Page Language vb AutoEventWireup false lt DOCTYPE HTML PUBLIC - W3C DTD HTML 4.0 Transitional EN gt lt html gt lt meta name GE gt ERATOR content Microsoft Visual Studio .NET 7.0 gt lt meta name CODE_LANGUAGE content Visual Basic 7.0 gt lt meta name vs defaultClientScript content JavaScript gt lt meta name vs targetSchema lt head gt lt body lt form id Form1 method post runat server gt lt form gt lt body gt lt html gt The code in Example 6-1 has the following qualities The Page directive at...

Example 51 Dynamically creating a Splitter control

Shared Sub AddSplitter ByVal ctl As Control ' Get the Controls collection of the given control's container. Dim controls As ctl.Parent.Controls ' Add the Splitter to the same container as the given control. controls.Add split ' Move the Splitter control to be immediately prior to the given ' control in the Controls collection. This causes the Splitter ' control's z-order to be just above the given control's z-order, ' which in turn means that the Splitter control will be docked ' immediately...

The Graphics Class

Objects of type Graphics defined in the System.Drawing namespace represent two-dimensional surfaces on which to draw. A Graphics object must be obtained before any drawing can be done. A common way to obtain a Graphics object is to override the OnPaint method of a form or user control, as shown in the following code fragment Public Class MyControl Inherits UserControl Protected Overrides Sub OnPaint ByVal e As PaintEventArgs e.Graphics.FillEllipse New SolidBrush Me.ForeColor ,...