PrintPreviewDialog
The PrintPreviewDialog component displays a dialog box that allows the user to view a document before printing it. Prior to showing the dialog box, the PrintPreviewDialog object must be loaded with information about the document to be printed. See Printing in Chapter 4 for details. The dialog box itself displays a preview of the printed version of the document, allowing the user to navigate through it. Figure 5-20 shows an example of the PrintPreviewDialog dialog box, although this example...
Description 1
Specifies whether the program element is CLS-compliant. The CLSCompliantAttribute class constructor is Public Sub New ByVal isCompliant As Boolean The isCompliant parameter indicates whether the program element is CLS-compliant. The CLSCompliantAttribute class has a single property Indicates whether the program element is CLS-compliant. The type is Boolean. See Chapter 3 for information on the CLS and on what it means for a program element to be CLS-compliant.
Comparison of Assemblies Modules and Namespaces
It's easy to confuse the three concepts of namespace, module, and assembly. Here is a recap Namespace A portion of a type name. Specifically, it is the portion that precedes the final period in a fully qualified type name. A file that contains executable code .exe or .dll . Assembly A set of one or more modules that are deployed as a unit. The assembly name is the same as the name of the module that contains the assembly manifest, minus the filename extension. Depending on how things are named,...
Example 82 Allowing an SqlDataAdapter object to infer SQL UPDATE INSERT and
' 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 ' 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...
Finding Rows
The DataTable object's Rows property holds a DataRowCollection object that in turn holds the table's DataRow objects. Each DataRow object holds the data for that particular row. The following code loops through all the rows in the DataTable and displays the value of the first column column 0 in the row This code does the same thing, using a numeric index on the RowsCollection object Console.WriteLine dt.Rows n 0 Next To assist with locating specific rows within a table, the DataTable class...
Hello Printer
Example 4-13 shows a minimal printing example. Example 4-13. Hello, Printer ' These two lines initiate printing. Place this code in an ' appropriate place in the application. Dim pd As New HelloPrintDocument pd.Print ' This class manages the printing process. Public Class HelloPrintDocument Inherits PrintDocument Protected Overrides Sub OnPrintPage ByVal e As PrintPageEventArgs MyBase.OnPrintPage e ' Draw text to the printer graphics device. Dim fnt As New Font Arial, 10, FontStyle.Regular,...
The OnBeginPrint and OnEndPrint Methods
The PrintDocument class provides the OnBeginPrint and OnEndPrint methods for managing the start and finish of print jobs. The OnBeginPrint method is called prior to the first call to OnPrintPage, and the OnEndPrint method is called after the final call to OnPrintPage. The OnBeginPrint method is a good place to set up objects that will be used throughout the life of the print job pens, brushes, and fonts, for example. The HelloPrintDocument class in Example 4-13 instantiates a Font object during...
The PrinterSettings 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...
The PageSettings Class
As mentioned earlier, the PrintPageEventArgs object passed to the OnPrintPage method has a PageSettings property that holds a PageSettings object. This object holds the settings applicable to printing a single page. The properties of the PageSettings class are Represents a rectangle that specifies the full area of the page, including the area outside the margins. This is the same value found in the PageBounds property of the PrintPageEventArgs class. The syntax of the Bounds property is Public...
The ListBox Class
The ListBox class represents a box that contains a list of items. The following are its more important properties This is a Boolean that indicates whether the listbox has more than one column. Its default value is False. In a multicolumn listbox, this property represents the width of each column in pixels. By default, the value of this property is zero, which makes each column have a default width. This is the most important property of the ListBox class. It returns the ListBox.ObjectCollection...
Programmatically Instantiating Controls
It's easy to dynamically instantiate server controls at runtime. A convenient place to do this is in an override of the OnPreRender method of the Page class. Recall that the OnPreRender method is called after the page and its controls have been instantiated and initialized but prior to any rendering. Controls created here and added to the Page object's Controls collection will be rendered on the page. The code is simple Protected Overrides Sub OnPreRender ByVal e As EventArgs ' Instantiate a...
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
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 ImageList 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 ListBoxObjectCollection 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...
Visual Basic Event Handler Scope
Scope refers to the so-called visibility of identifiers within source code. That is, given a particular identifier declaration, the scope of the identifier determines where it is legal to reference that identifier in code. For example, these two functions each declare a variable CoffeeBreaks. Each declaration is invisible to the code in the other method. The scope of each variable is the method in which it is declared. Public Sub MyFirstMethod Dim CoffeeBreaks As Integer Public Sub...
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...
Example 84 Creating a DataRelation between DataTables in a DataSet
' 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 Dim strSql As String SELECT FROM Customers _ amp WHERE City 'Buenos Aires' AND Country 'Argentina' Dim da As SqlDataAdapter New SqlDataAdapter strSql, cn Dim ds As DataSet New DataSet da.Fill ds, Customers ' Set up a new data adapter object. strSql SELECT Orders. _ amp FROM Customers, Orders _ amp...
The DateTimePicker Class
The DateTimePicker class represents a control that allows users to select a date in the calendar, just like the MonthCalendar control. Unlike MonthCalendar, however, the DateTimePicker control only displays a box, which looks like a combo box, containing the selected date. When the user clicks the arrow, the control displays a drop-down calendar similar to the MonthCalendar control, from which the user can select a date. This drop-down portion closes as soon as the user selects a date. The user...
The WebMethod 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...
OpenFileDialog
The OpenFileDialog component displays a dialog box that allows the user to choose a file to open. After the user clicks OK, the name of the file including the path is available in the OpenFileDialog object's FileName property. The FileName property can be set prior to showing the dialog box. This causes the dialog box to initially display the given filename. Figure 5-16 shows an example of the OpenFileDialog dialog box. Figure 5-16. The OpenFileDialog dialog box Figure 5-16. The OpenFileDialog...
Relations Between DataTables in a DataSet
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 ,...
Windows authentication
With Windows authentication, the ASP.NET runtime lets IIS and the Windows operating system handle user authentication. Three kinds of authentication come under this category Integrated Windows authentication, Digest authentication, and Basic authentication. To use one of these authentication methods, the web site in IIS must be set to disallow anonymous access, and one or more of these three authentication mechanisms must be enabled. If more than one is enabled, the most secure...

