Using a Stream Writer to Save Control Values to a File

To get started with saving the Text values of controls, add two buttons to the form, called btnWriteControls and btnReadControls. Next, add a bunch of TextBoxes to the form. These will be used for writing and retrieving values. It really doesn't matter what they are called or what values they show initially, so you can accept the default names and values TextBox1, TextBox2, and so on . It also doesn't matter how many or few there are, because the StreamWriter object, using the code I'll show...

Using XMLSerializer

Object Oriented Programming Net

Under the hood, VB .NET and XML work hand and glove together. This can be seen in a quite simple example using an XMLSerializer object to serialize an instance of a class to a StreamReader which can save it as file . The XMLSerializer can also be used in a reverse fashion to convert or deserialize an I O stream, pulled from a file with a StreamWriter object, back to an instance of a class, making the members of the object programmatically available. For more information about working with...

Adding Client Side Scripting

You may also be interested to know that the HTML tab of the designer provides a framework via the Objects and Procedures lists for adding client-side scripting, using JavaScript. For example, try selecting Window from the objects shown under Client Objects amp Events drop-down list in the upper-left side of the designer. Next, choose Onclick from the drop-down list of events in the Procedures list. -. - . 1 Lfl - ki. h lua LI hill I ,1 L ILLl r rci -nftnit-llmTOlii 74 wt iN rrii-rnimicc jgrt m...

Using Predefined Color Values

In VB6, color values were stored as long integers specifically, they were typed as Long . In other words, every color that you could use was reduced to a numerical value. In contrast, in VB .NET, colors are stored as two new types System.Drawing.Color and System.Drawing.SystemColors. Both types return a color structure that contains the color value as a 32-bit number. You can use the members of the System.Drawing.Color and System.Drawing.SystemColors classes as predefined color values in your...

Setting the Back Color

Various color properties can be set to change the color of elements of a form. For example, the BackColor property sets the background color used in a form. By default, it is set to a color determined by the Windows System color scheme, as shown here. j Tin hrfKjftfH C M jlnil ID 41 4n It Ift 11 ir A GMMiil. You can also set BackColor to a color of your choice using the Custom palette Another option is to set BackColor to a color that is designed to display well on the Web well, actually in...

Throwing Exceptions

Throwing an exception means creating your own exception under certain conditions. It is comparable to raising an error in VB6. Throwing custom exceptions should not be done to facilitate normal program communication, but it may make sense as part of a scheme for dealing with logical errors, and it is what your application should do in many circumstances if it asked to do something impossible. To throw an exception, use the Throw keyword with a new instantiation of the Exception class, or one of...

Reading XML with XMLText Reader

The counterpart to the XMLTextWriter class is the XMLTextReader class. Realize that this is by no means the only class available in .NET to read or parse XML files XMLNodeReader and XMLValidatingReader are also powerful classes. Much of the time, you will know a great deal about the formatting of the XML file you want to read. That's certainly the case with the example that I'll show you, in which we know that the root element is named lt UserChoice gt and is followed by elements and values...

Finishing the Web Setup Project

After you've run the Setup Wizard to create your Web Setup project, you can then add the project output to the Setup project. Select the root node of the Setup project, right-click, and select Add Project Output. In the Add Project Output dialog, make sure Primary Output is selected, as shown in Figure 20.10, and click OK. igure 20.10 The Add Project Output Group dialog is used to add the output of the Web Setup project to the solution. Next, make changes to the Web Setup project settings using...

Creating a Web Service

In theory, a sample web service could do anything you can do in a class module, from the trivial to the very useful. Our web service will determine if the number input is a prime not evenly divisible by another number except one or itself . First, use the New Project dialog to create an ASP.NET Web Service project named IsPrime, as shown in Figure 19.10. amp gt Web A3 - per tffb Web Cortrd ApficflfcOT SenrtM Lbr-wr I Hit rJii.iVlniil pumu J I- it iep jiKitim ljfvii , 'igure 19.10 Web services...

Monitoring Form Closing Events

Does closing sound more tentative to you than closed In the brave new world of events, it is indeed. The Closing event gives the programmer a chance to allow the user to change her mind see the Unloading Forms section later in this chapter , while the Closed event is the real thing the form is gone. As this implies, Closed comes after Closing in the sequence, with Deactivate in between. You can add calls to the Debug.WriteLine method to observe this, as shown in Listing 5.4. Listing 5.4...

Manipulating Menus in Code

One of the easiest ways to manipulate menus in response to application state is to add a second MainMenu control to the form and toggle between the two menu structures. To see an example of this in action, add a Toggle Menus menu item to the original MainMenu structure we've created. Next, add a new MainMenu control to the form. As you can see, the menu items that make up this menu structure are pretty fantastic, so let's give the menu item that toggles back to the first menu the text Back to...

Using the RGB Function

Code Color 255 192 192

Let's suppose you want to mix your own colors rather than using a predefined constant value. You can do this, but it's slightly tricky. First of all, let's have a quick look at RGB, or Red Green Blue, color notation. In RGB color notation, each primary component color red, green, and blue is represented by a number between 0 and 255. Table 4.2 shows some of the most common RGB values, but, of course, you can use the notation to represent almost any color. If you use the Properties window to...

Appendix C Key Syntax Differences Between VB6 and VB NET

There are a great many differences between VB6 and VB .NET. In some ways, the most important changes are conceptual, rather than having to do with syntax or language. To understand these changes, a good starting place is to read this book. Another useful reference is the Introduction to Visual Basic .NET for Visual Basic Veterans Help topic and the links within that topic. See Appendix A, Using VB .NET's Help System. This appendix lists most of the changed programming elements and their...