Microsoft KB Archive/315849

= Programming Microsoft Windows With C# Comments And Corrections =

Article ID: 315849

Article Last Modified on 9/28/2004

-

APPLIES TO


 * MSPRESS Programming Microsoft Windows With C# ISBN 0-7356-1370-2

-



This article was previously published under Q315849



SUMMARY
This article contains comments, corrections, and information about known errors relating to the Microsoft Press book Programming Microsoft Windows With C#, ISBN 0-7356-1370-2.

The following topics are covered:


 * CD-ROM: New ImageIO.cs And MetafileConvert.cs Files
 * Page 4: Creating An Empty Project Only Valid For Visual Studio.Net
 * Page 12: Typographical Error
 * Page 14: Correction To AddFive Routine
 * Page 45: Int16 Should Be Int32
 * Page 56: Missing &quot;)&quot; In Code Sample
 * Pages 116 & 118: SystemColor Should Be SystemColors
 * Page 203: Incorrect Chapter Cross-Reference In First Paragraph On Page
 * Page 244: Incorrect Capitalization In Code Sample
 * Pages 252 and 253: Incorrect Hebrew Character Leading To Misspelling Of &quot;Boker&quot;
 * Page 289: Incorrect Square Roots Within Graphic At Top Of Page
 * Page 298: OnPage Should Be DoPage
 * Page 382: Remove Extra Space From Code
 * Page 403: Two Incorrect Values In TestRenderingHint Enumeration Table
 * Page 416: How the DrawString Should Be How does the Drawstring
 * Page 472: Error In Code Sample
 * Page 484: Out-of-date Info In Paragraph
 * Page 489: Incorrect URL
 * Page 515: Correction To Save Method
 * Page 770: Single Class Should Be Single Structure
 * Pages 779 and 780: Correction To ImageIO.cs Code
 * Pages 1112 and 1113: Correction to MetafileConvert.cs Code
 * Page 1118: Filename Is Stored As String



Page 4: Creating An Empty Project Only Valid For Visual Studio.Net
On page 4, there is a description on how to create an empty project. The option of creating an empty project is available with Visual Studio .NET, but not with Visual C# .NET Standard Edition.

We have made available a file that allows you to add an empty project in Visual C# .Net.

Download and save the file emptypro.exe onto your hard disk, then double-click the file to extract the file CSharpExForEmptyProject.vsdir into the \Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjects folder.

The following file is available for download from the Microsoft Download Center:

emptypro.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

CD-ROM: New ImageIO.cs And MetafileConvert.cs Files
On the companion CD, files ImageIO.cs (\Code\Dialog Boxes\ImageIO) and MetafileConvert.cs (\Code\Metafiles\MetafileConvert) contain errors in their code. The files with the corrected code are available now for download.

The following file is available for download from the Microsoft Download Center:

Code.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on secure servers that prevent any unauthorized changes to the file.

Page 12: Typographical Error
There is a typographical error on page 12 in the second-to-the-last paragraph. Change:

&quot;Date types don't need...&quot;

To:

&quot;Data types don't need...&quot;

Page 14: Correction To AddFive Routine
On page 14, in the AddFive routine,

Change:

&quot;i + 5;&quot;

To:

&quot;i += 5;&quot;

Page 45: Int16 Should Be Int32
There are two incorrect references to Int16 in the middle of page 45.

Change:

&quot;is an alias for the Int16 structure.&quot;

To:

&quot;is an alias for the Int32 structure.&quot;

Also change:

&quot;System.Int16 a = 55;&quot;

To:

&quot;System.Int32 a = 55;&quot;

Page 56: Missing &quot;)&quot; In Code Sample
There is an error in the &quot;switch and case&quot; construction coding example at the bottom of page 56. The end of line four is missing a closing parenthesis.

Change:

switch (MessageBox.Show(&quot;Do you want to create a new file?&quot;, &quot;WonderWord&quot;, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

{ case DialogResult.Yes: // &quot;Yes&quot; processing break;

To:

switch (MessageBox.Show(&quot;Do you want to create a new file?&quot;, &quot;WonderWord&quot;, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))

{ case DialogResult.Yes: // &quot;Yes&quot; processing break;

Pages 116 & 118: SystemColor Should Be SystemColors
There is an error in the code samples on page 116 and 118. The four instances total of &quot;SystemColor&quot; on pages 116 and 118 should be changed to &quot;SystemColors&quot;.

Page 203: Incorrect Chapter Cross-Reference In First Paragraph Of Page
In the first paragraph on page 203, in the fourth line,

Change:

&quot;find out about in Chapter 11....&quot;

To:

&quot;find out about in Chapter 13....&quot;

Page 244: Incorrect Capitalization In Code Sample
The beginning of the Caret class towards the bottom of Page 244 contains five instances of the following program instruction:

[DLLImport(&quot;user32.dll&quot;)]

When the reader attempts to compile the Caret.cs file, the following error message is thrown:

...\Caret.cs(13): The type or namespace name 'DLLImport' could not be found (are you missing a using directive or an assembly reference?)

The reason the compiler generated this error is because the two letter &quot;L's&quot; in the word &quot;DLLImport&quot; are capitalized. (Please note an example of the proper way to write this statement can be found on the sixth line of Page 239.)

Error Solution:

Change the two upper case letter &quot;L's&quot; to lower case letter &quot;l's.&quot;

Correction:

The beginning of the Caret class towards the bottom of Page 244 should contain five instances of the following program instruction: [DllImport(&quot;user32.dll&quot;)]

Pages 252 and 253: Incorrect Hebrew Character Leading To Misspelling Of &quot;Boker&quot;
In the second paragraph of the &quot;Right-to-Left Problems&quot; section on page 252, in the second line, replace the sentence that is there with the following:

&quot;We're going to type the Hebrew for 'good morning,' which is בוקר טוב, commonly transliterated as boker tov.&quot;

In the second sentence of the second paragraph under the table on page 253, replace the sentence &quot;So to type...(the c key).&quot; with the following:

&quot;So, to type the Hebrew phrase shown above into TypeAway, you need to type the letters in this order: bet (the c key), vav (the u key) qof (the e key), resh (the r key), space, tet (the y key), vav (the u key), and bet (the c key).&quot;

Page 289: Incorrect Square Roots Within Graphic At Top Of Page
On page 289, in the graphic (G07PL09) on the top of page 289, all instances (8) showing the square root of 2 should instead show the square root of 1/2.

Page 298: OnPage Should Be DoPage
There are two typographical errors at the bottom of page 298.

Change:

&quot;The OnPage method changes...&quot;

To:

&quot;The DoPage method changes...&quot;

Change:

&quot;OnPage then switches...&quot;

To:

&quot;DoPage then switches...&quot;

Page 382: Remove Extra Space From Code
The seventh line from the end of the AllAboutFont.cs program located on Page 382 states:

&quot;GdiVerticalFont : &quot; + Font.GdiVerticalFont + &quot;\n&quot; +

Remove the space between the Font property and the colon character in the aforementioned line and in the program's output display window at the bottom of Page 382.

This line should read:

&quot;GdiVerticalFont: &quot; + Font.GdiVerticalFont + &quot;\n&quot; +

Page 403: Two Incorrect Values In TestRenderingHint Enumeration Table
On page 403, In the TextRenderingHint Enumeration table, the fourth and fifth lines should be switched and the values in the second column changed. Change the fourth row from:

&quot;AntiAlias 3 Anti-aliasing, no grid fitting&quot;

To:

&quot;AntiAliasGridFit 3 Anti-aliasing with grid fitting&quot;

And Change the fifth row from:

&quot;AntiAliasGridFit 4 Anti-aliasing with grid fitting&quot;

To:

&quot;AntiAlias 4 Anti-aliasing, no grid fitting&quot;

Page 416: How the DrawString Should Be How does the Drawstring
There is a typographical error in the middle of page 416.

Change:

&quot;How the DrawString call interprets ampersands?&quot;

To:

&quot;How does the DrawString call interpret ampersands?&quot;

Page 472: Error In Code Sample
On page 472, there is an error in the JeuDeTaquin.cs code sample.

Change:

&quot;BorderStyle = FormBorderStyle.Fixed3D;&quot;

To:

&quot;FormBorderStyle = FormBorderStyle.Fixed3D;&quot;

Page 484: Out-of-date Info In Paragraph
On page 484, in the section titled “Bitmap File Formats&quot;,

Change:

&quot;Exif The Exchangeable image format was developed by the organization now known as Japan Electronic Industry Development Association (JEIDA) for use in digital cameras. The specification is published on the Web site of the International Imaging Industry Association (I3A), formerly the Photographic and Imaging Association, Inc. (PIMA) at http://www.pima.net/standards/it10/PIMA15740/Exif_2-1.PDF.&quot;

To:

&quot;Exif The Exchangeable image format was developed by the organization now known as Japan Electronics and Information Technology Industries Association (JEITA) for use in digital cameras. The specification for EXIF 2.2 can be found here: http://www.exif.org/Exif2-2.PDF. &quot;

Page 489: Incorrect URL
The ImageFromWeb.cs program defines an incorrect string variable named 'strUrl' located approximately in the middle of Page 489.

Change:

&quot;string strUrl =

&quot;http://images.jsc.nasa.gov/images/pao/AS11/10075267.jpg&quot;;&quot;

To:

&quot;string strUrl =

&quot;http://images.jsc.nasa.gov/lores/AS11-40-5903.jpg&quot;;&quot;

Page 515: Correction To Save Method
On page 515, in first paragraph under &quot;More on the Image Class&quot;, remove:

&quot;The first version of Save in the following list uses the filename extension to determine the file Format, but you can be more explicit in the next two versions:

...

void Save(string strFilename)&quot;

Page 770: Single Class Should Be Single Structure
There is an incorrect statement in the middle of the third paragraph on page 770.

Change:

&quot;The point size has to be converted from a string back to a float using the static Parse method of the Single class.&quot;

To:

&quot;The point size has to be converted from a string back to a float using the static Parse method of the Single structure.&quot;

Pages 779 and 780: Correction To ImageIO.cs Code
On pages 779 and 780, replace the ImageIO.cs code with the following: //-- // ImageIO.cs (c) 2001 by Charles Petzold //-- using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms;

class ImageIO: ImageOpen {    MenuItem miSaveAs;

public new static void Main {         Application.Run(new ImageIO); }    public ImageIO {         Text = strProgName = &quot;Image I/O&quot;;

Menu.MenuItems[0].Popup += new EventHandler(MenuFileOnPopup); miSaveAs = new MenuItem(&quot;Save &As...&quot;); miSaveAs.Click += new EventHandler(MenuFileSaveAsOnClick); Menu.MenuItems[0].MenuItems.Add(miSaveAs); }    void MenuFileOnPopup(object obj, EventArgs ea) {         miSaveAs.Enabled = (image != null); }    void MenuFileSaveAsOnClick(object obj, EventArgs ea) {         SaveFileDialog savedlg = new SaveFileDialog;

savedlg.InitialDirectory = Path.GetDirectoryName(strFileName); savedlg.FileName = Path.GetFileNameWithoutExtension(strFileName); savedlg.AddExtension = true; savedlg.Filter = &quot;Windows Bitmap (*.bmp)|*.bmp|&quot; + &quot;Graphics Interchange Format (*.gif)|*.gif|&quot; + &quot;JPEG File Interchange Format (*.jpg)|&quot; + &quot;*.jpg;*.jpeg;*.jfif|&quot; + &quot;Portable Network Graphics (*.png)|*.png|&quot; + &quot;Tagged Imaged File Format (*.tif)|*.tif;*.tiff&quot;;

ImageFormat[] aif = { ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff };

if (savedlg.ShowDialog == DialogResult.OK) {              try {                   image.Save(savedlg.FileName, aif[savedlg.FilterIndex - 1]); }              catch (Exception exc) {                   MessageBox.Show(exc.Message, Text); return; }              strFileName = savedlg.FileName; Text = strProgName + &quot; - &quot; + Path.GetFileName(strFileName); }    } }

Pages 1112 and 1113: Correction to MetafileConvert.cs Code
On pages 1112 and 1113, replace the MetafileConvert.cs code with the following: //-- // MetafileConvert.cs (c) 2001 by Charles Petzold //-- using System; using System.Drawing; using System.Drawing.Imaging; using System.IO;             // For Path class using System.Windows.Forms;

class MetafileConvert: MetafileViewer {    public new static void Main {         Application.Run(new MetafileConvert); }    public MetafileConvert {         Text = strProgName = &quot;Metafile Convert&quot;; }    protected override void MenuFileSaveAsOnClick(object obj, EventArgs ea) {         SaveFileDialog dlg = new SaveFileDialog;

if (strFileName != null && strFileName.Length > 0) dlg.InitialDirectory = Path.GetDirectoryName(strFileName);

dlg.FileName = Path.GetFileNameWithoutExtension(strFileName); dlg.AddExtension = true; dlg.Filter = &quot;Windows Bitmap (*.bmp)|*.bmp|&quot; + &quot;Graphics Interchange Format (*.gif)|*.gif|&quot; + &quot;JPEG File Interchange Format (*.jpg)|&quot; + &quot;*.jpg;*.jpeg;*.jfif|&quot; + &quot;Portable Network Graphics (*.png)|*.png|&quot; + &quot;Tagged Image File Format (*.tif)|*.tif;*.tiff&quot;;

ImageFormat[] aif = { ImageFormat.Bmp, ImageFormat.Gif, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff };

if (dlg.ShowDialog == DialogResult.OK) {              Bitmap bm = MetafileToBitmap(mf);

try {                   bm.Save(dlg.FileName, aif[dlg.FilterIndex - 1]); // bm.Save(dlg.FileName); }              catch (Exception exc) {                   MessageBox.Show(exc.Message, Text); }         }     }     Bitmap MetafileToBitmap(Metafile mf) {         Graphics grfx = CreateGraphics; int cx = (int) (grfx.DpiX * mf.Width / mf.HorizontalResolution); int cy = (int) (grfx.DpiY * mf.Height / mf.VerticalResolution); Bitmap bm = new Bitmap(cx, cy, grfx); grfx.Dispose;

grfx = Graphics.FromImage(bm); grfx.DrawImage(mf, 0, 0, cx, cy); grfx.Dispose;

return bm; } }

Page 1118: Filename Is Stored As String
There is an incorrect statement at the bottom of page 1118.

Change:

&quot;Instead, the filename is stored as a file and the...&quot;

To:

&quot;Instead, the filename is stored as a string and the...&quot;

Microsoft Press is committed to providing informative and accurate books. All comments and corrections listed above are ready for inclusion in future printings of this book. If you have a later printing of this book, it may already contain most or all of the above corrections.

Additional query words: DEVBOOK Petzold 0-7356-1370-2

Keywords: kbinfo kbdownload kbfix KB315849

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.