15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OC48 ❘ ChaPTer 48 GrAphics with Gdi+<br />

figure 48-20<br />

summary<br />

This chapter covered the realm of GDI+ — the area of drawing to a display device, where the drawing is<br />

done by your code rather than by some predefined control or dialog box. GDI+ is a powerful tool, <strong>and</strong><br />

there are many .<strong>NET</strong> base classes available to help you draw to a device. You have seen that the process of<br />

drawing is actually relatively simple. In most cases, you can draw text or sophisticated figures or display<br />

images with just a couple of <strong>C#</strong> statements. However, managing your drawing — the behind-the-scenes<br />

work involving working out what to draw, where to draw it, <strong>and</strong> what does or does not need repainting<br />

in any given situation — is far more complex <strong>and</strong> requires careful algorithm design. For this reason, it is<br />

also important to have a good underst<strong>and</strong>ing of how GDI+ works <strong>and</strong> what actions Windows takes to<br />

get something drawn. In particular, because of the architecture of Windows, it is important that, where<br />

possible, drawing should be done by invalidating areas of the window <strong>and</strong> relying on Windows to respond<br />

by issuing a Paint event.<br />

Many more .<strong>NET</strong> classes can be used for drawing than there is space to cover in this chapter. However,<br />

if you have worked through it <strong>and</strong> understood the principles involved in drawing, then you will be in an<br />

excellent position to explore these classes by looking at their lists of methods in the SDK documentation <strong>and</strong><br />

instantiating instances of them to see what they do. In the end, drawing, as with almost any other aspect of<br />

programming, requires logic, careful thought, <strong>and</strong> clear algorithms if you want to go beyond the st<strong>and</strong>ard<br />

controls. Your software will benefit in both user-friendliness <strong>and</strong> visual appearance if it is well thought out.<br />

Many applications out there rely entirely on controls for their user interface. Although this can be effective,<br />

such applications very quickly end up resembling each other. By adding some GDI+ code to do some custom<br />

drawing you can mark out your software as distinct <strong>and</strong> make it appear more original, which can only help<br />

increase your sales!<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!