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.

new Controls <strong>and</strong> Dialogs ❘ 1407<br />

If you just follow the simple rule not to use hard - coded path values with the program, it doesn ’ t matter<br />

where the real folders are located. The folders differ with different Windows languages anyway. For special<br />

folders, use the Environment class <strong>and</strong> the SpecialFolder enumeration:<br />

string folder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);<br />

Some of the folders defi ned by the SpecialFolder enumeration are described in the following table.<br />

ConTenT sPeCialfolder enumeraTion WindoWs 7 defaulT direCTory<br />

User-specifi c documents Personal C:\Users\\Documents<br />

User-specifi c data for roaming<br />

users<br />

User-specifi c data that is local<br />

to a system<br />

ApplicationData<br />

LocalApplicationData<br />

C:\Users\\AppData\Roaming<br />

C:\Users\\Appdata\Local<br />

Program fi les ProgramFiles C:\Program Files<br />

Program fi les that are shared<br />

among different programs<br />

Application data common to<br />

all users<br />

CommonProgramFiles<br />

CommonApplicationData<br />

C:\Program Files\Common Files<br />

C:\ProgramData<br />

At logoff, the content of roaming directories is copied to the server, so if the user<br />

logs on to a different system, the same content is copied <strong>and</strong> is, thus, available on all<br />

systems accessed by the user.<br />

With the special folders, you must be careful that a normal user doesn ’ t have write access to the program<br />

fi le s d i re c tor y. You c a n w r it e u s er - sp e c i fi c d at a f rom t he appl ic at ion to LocalApplicationData , or for<br />

roaming users, to ApplicationData . Data that should be shared among different users can be written to<br />

CommonApplicationData .<br />

neW ConTrols <strong>and</strong> dialogs<br />

Windows Vista <strong>and</strong> Windows 7 deliver several new controls. The comm<strong>and</strong> link control is an extension<br />

to the Button control <strong>and</strong> is used in combination with several other controls. The task dialog is a next -<br />

generation MessageBox , <strong>and</strong> for opening <strong>and</strong> saving fi les, new dialogs are available as well.<br />

Comm<strong>and</strong> link<br />

Comm<strong>and</strong> link controls are an extension of the Windows Button control. Comm<strong>and</strong> links contain an<br />

optional icon <strong>and</strong> note text. This control is often used in task dialogs <strong>and</strong> wizards <strong>and</strong> gives much more<br />

information than button controls with OK <strong>and</strong> Cancel content.<br />

With .<strong>NET</strong> applications, you can create comm<strong>and</strong> link controls by using the Windows API Code Pack.<br />

If you add the project Microsoft.WindowsAPICodePack.Shell to your solution, you can add a Windows<br />

Forms Comm<strong>and</strong>Link controls from the toolbox to your Windows Forms application. The class Comm<strong>and</strong>Link<br />

derives from the System.Windows.Forms.Button class. A comm<strong>and</strong> link is an extension of the native<br />

Windows Button <strong>and</strong> defi nes additional Windows messages <strong>and</strong> a new style to confi gure the Button . The<br />

wrapper class Comm<strong>and</strong>Link sends the Windows messages BCM_SETNOTE <strong>and</strong> BCM_SETSHIELD <strong>and</strong> sets<br />

the style BS_COMMANDLINK . The public methods <strong>and</strong> properties offered in addition to the members of the<br />

Button class are NoteText <strong>and</strong> ShieldIcon .<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!