Page #118 (Why C Games Dont Use Bitmaps)

 

Overview

The PictureBox is one of the controls in the Toolbox. When it is first placed on a template it looks just like the panel. It has no border initially, so the programmer must apply a border by highlighting the picture box (to place its properties in the Properties window), picking Appearance | Border Style, and choosing the Fixed Single option.

Below Border Style there is an Image entry area that allows you to place a *.bmp or *.png graphic into the project. (A .png is a Microsoft invention, and it works just like a .bmp.) If you click on Image, be prepared to browse for the name of a bitmap to place in the PictureBox control.

To view project Picture Box, enter the IDE and click on File on the main menu, followed by Open | Project/Solution. When the Open Project window opens, click on the Picture Box subdirectory in Visual Studio 2005\Projects\DemosSourceCode. As soon as the project enters the IDE, compile and run it. The main window looks like Figure 28-1. In this case the necessary *.png file, CogTrain2.PNG, was placed in the folder Visual Studio 2005\Projects\DemosSourceCode\Picture Box\bin\debug. This .png file is located in the same directory as PictureBox.exe.

image from book
Figure 28-1: Picture Box window

If the graphic is too large to fit into the PictureBox control, it will simply overflow on all sides. There is no device in the Visual Studio C# compiler to make the picture fit exactly in the picture box.

What about the small panel at the lower center of the picture? What is that? This is a simple panel (not a picture box). We have no bitmap to place in this area, so it must remain blank. If we had created a second picture box (by dropping another picture box from the Toolbox onto the window template), then the second picture box would have shown under the first picture box ” there is no way to force a second picture on top of the first picture. We did this to give you an idea of how hard it is to manipulate bitmap pictures on the screen.

If you had access to an image editor apart from the Visual Studio C# compiler, you could create a bitmap, place it onto the panel, then move the panel about on the screen. But this takes more tools than you possess ” more software to buy, probably from a third-party vendor.

The Visual Studio C# compiler has statements that will index through a series of bitmaps to cause a picture to animate, but the sequence of bitmaps must be created elsewhere. Perhaps later versions of the Visual Studio C# compiler will include more tools to do this type of work.

 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net