Making a Square Window Round

Next, within the form class code, create a procedure, ApplyInitialRegion. Within ApplyInitialRegion, define a GraphicsPath object using its AddEllipse method, and assign it to the Region property of the Form object. GraphicsPath myGraphicsPath new GraphicsPath myGraphicsPath.AddEllipse new Rectangle 0, 0, 600, 450 this.Region new Region myGraphicsPath All that remains is to create a way to call the form, which you can do in a button Click event, as shown in Listing 3.9. When the click event is...

Creating a Nonzero Lower Bound

I teased you towards the beginning of the chapter by saying I would show you how to create an array with a non-zero lower bound. Here goes Warning You probably won't want to use non-zero lower bounds very often in C , because arrays created in the way shown in this example do not have many of the conveniences-such as square bracket notation-that we've come to expect when working with arrays. First, you need to create two integer arrays. The first array is used to store in its elements the size...

Programmatically Creating and Validating a Schema

Before I show you how to use the XmlSchema class to create and validate a schema, let's define the schema manually. To put the cart even further before the horse, let's first create some XML that we'd like to be the basis for the schema, and describe how we'd like the XML to work in fact, this is likely to be the way schemas are created in the real world . My XML excerpt describes a product, which is an element that is a complex type. Each product must have an integer product identification...

Binary Files

The user interface shown in Figure 10.9 is used to demonstrate reading and writing binary files. Once again, common dialogs let the user select files for reading or writing. A ht ' J lio cj 1 WMtlfcart ht V gt 2 Pu-t Jo igure 10.9 Text is saved and retrieved using binary files. Out of pure orneriness, I've elected to demonstrate saving and retrieving text to and from binary files. If you knew it was text, you probably wouldn't want to do it this way, since working with StreamReaders and...

Using the WSDL Utility

To invoke the WSDL utility, wsdl.exe, first open the Visual Studio .NET Command Prompt window. You'll find it on your Windows Start menu under Microsoft Visual Studio .NET Visual Studio .NET Tools. To see all the command-line switches available with the utility, at the prompt type wsdl and press Enter. To create a proxy, enter wsdl, followed by the language choice CS for C and VB for Visual Basic , and then the URL of the web service with WSDL appended. For example wsdl language CS wsdl...

Using a Property to Pass a Form Instance

Properties are ideal for holding a reference to a class instance in a second form class. To see how this works, use the Add New Item dialog to add a new form to a Windows application project. If you didn't change their default names, you now have two forms-and classes-in the project named Form1 and Form2. Before we get started, use the Properties window to change the value of the Text property of Form1 to something like The first form is very happy . We'll be accessing this value from the Form2...

Subclassing a Message

Supposing you do want to do something with a Windows message, it is easy enough. To see how, let's write a very short override to WndProc that intercepts the WM_MOUSEMOVE and WM_MOUSELEAVE messages. The first of these is sent when the mouse moves on a window, the second when the mouse cursor leaves a window. The value of the ID stored in the Msg parameter for WM_MOUSEMOVE is hexadecimal 0x200, and WM_MOUSELEAVE is 0x2a3. This can be seen in the Debug output shown in Figure 11.3. Translating...

Polymorphism Demonstration

Let's have a simple polymorphism dino-oops, I mean demo-in the context of dinosaurs. Jared Diamond, in Guns, Germs, and Steel, quotes the famous first sentence of Tolstoy's Anna Karenina 'Happy families are all alike every unhappy family is unhappy in its own way.' Well, let's also assume that all dinosaurs are pretty much alike, that they all have something called the GetFood method-which happens to return a string-and that each species of dinosaur implements its GetFood method differently...

Implementing the ICarnivore Interface

Kicking this all up a notch, let's implement our own interface. Since it is ours, we get to name it and to define its members. Let's make an ICarnivore interface that consists of the Boolean property EatMeat already implemented in the Dinosaur class and a Boolean method CanIEatU, which determines whether one dinosaur instance can eat another. Listing 9.11 shows the interface definition. Note It's worth saying explicitly that the interface definition only defines the members required for the...