15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working with Visual studio 2010 ❘ 389<br />

Visual Studio 2010 provides a toolbox with a large number of components<br />

that are available for your development purposes. The categories of<br />

components available through the toolbox depend, to some extent, on the<br />

type of project you are editing — for example, you will get a far wider<br />

range when you are editing the WindowsFormsApplication1 project<br />

in the DemoSolution solution than you will when you are editing the<br />

ConsoleApplication1 project. The most important ranges of items<br />

available include the following:<br />

➤<br />

Data — Classes that allow you to connect to data sources <strong>and</strong><br />

manage the data they contain. Here, you will find components<br />

for working with Microsoft SQL Server, Oracle, <strong>and</strong> any OleDb<br />

data source.<br />

➤ Windows Forms Controls (labeled as Common Controls) —<br />

Classes that represent visual controls such as text boxes, list boxes,<br />

or tree views for working with thick-client applications.<br />

➤<br />

➤<br />

Web Forms Controls (labeled as St<strong>and</strong>ard) — Classes that basically<br />

do the same thing as Windows controls but work in the context of<br />

web browsers, <strong>and</strong> that work by sending HTML output to simulate<br />

the controls to the browser. (You will see this only when working<br />

with ASP.<strong>NET</strong> applications.)<br />

Components — Miscellaneous .<strong>NET</strong> classes that perform various<br />

useful tasks on your machine, such as connecting to directory<br />

services or to the event log.<br />

You can also add your own custom categories to the toolbox by rightclicking<br />

any category <strong>and</strong> selecting Add Tab from the context menu.<br />

You can also place other tools in the toolbox by selecting Choose Items<br />

from the same context menu — this is particularly useful for adding your<br />

favorite COM components <strong>and</strong> ActiveX controls, which are not present<br />

figure 16-17<br />

in the toolbox by default. If you add a COM control, you can still click<br />

to place it in your project just as you would with a .<strong>NET</strong> control. Visual<br />

Studio automatically adds all the required COM interoperability code to allow your project to call up the<br />

control. In this case, what is actually added to your project is a .<strong>NET</strong> control that Visual Studio creates<br />

behind the scenes <strong>and</strong> that acts as a wrapper for your COM control.<br />

To see how the toolbox works, place a text box in your basic form project. You simply click the TextBox<br />

control contained within the toolbox <strong>and</strong> then click again to place it in the form in the design view (or if<br />

you prefer, you can simply drag <strong>and</strong> drop the control directly onto the design surface). Now the design view<br />

looks like Figure 16-18, showing roughly what WindowsFormsApplication1 will look like if you compile<br />

<strong>and</strong> run it.<br />

If you look at the code view of your form, you can see that Visual Studio 2010 does not add the code that<br />

instantiates a TextBox object to go on the form directly as it did in the early versions of the IDE. Instead,<br />

you will need to exp<strong>and</strong> the plus sign next to Form1.cs in the Visual Studio Solution Explorer. Here, you<br />

will find a file that is dedicated to the design of the form <strong>and</strong> the controls that are placed on the form —<br />

Form1.Designer.cs. In this class file, you will find a new member variable in the Form1 class:<br />

partial class Form1<br />

{<br />

private System.Windows.Forms.TextBox textBox1;<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!