Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Inside Microsoft® Visual Studio® .NET 2003 [Electronic resources] - نسخه متنی

Brian Johnson

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










Programming Help


A number of features in the IDE make it easier for programmers to write code. You should be familiar with Help in the IDE, so we won't talk too much about it. Help in Visual Studio .NET is dead simpleyou just select what you don't understand and press F1. You almost always get what you're looking for. In this section, we'll go over some of the features of the IDE that you've probably used but that you might not be so familiar with.


The Power of F1


A true story: A guy called me a few years ago and told me he'd been trying to find out why he was getting a Visual Basic error code when he was running some function (in Visual Basic 4, I think). He told me he'd been searching for an answer for hours and then finally called me for help. He e-mailed me his project, and I ran it while we talked. Sure enough, I got the same error. He heard my machine ding, and about 10 seconds later I told him what the error message meant. "How did you find that?!" the caller asked in amazement. I told him that I pressed F1 while the message box was still open.


IntelliSense


IntelliSense is one of those features that you start to rely on utterly as a programmer. It's a time-saving feature that can really help you do the right thing when you're typing code into the IDE. What IntelliSense does is provide statement completion in the form of context-sensitive member lists that appear automatically as you type code into the Code Editor. These lists can save you a ton of time when you're programming an unfamiliar API, and they can help you reduce errors that would normally be caught only at build time.

IntelliSense works by parsing the code you type into the Code Editor based on the project type context. This means that your source file needs to be part of a project or a solution before IntelliSense kicks in. IntelliSense is mostly automatic. It works on code that's part of the .NET Framework, and it works on external methods from references you've added to your project. It even works on XML Web services references that have been added to a project.

IntelliSense provides four major types of functionality when you're working with a supported language. Most programmers will use four of these featuresstatement completion, parameter information, word completion, and code commentsin their automatic form; that is, they'll take the information as presented in the IDE without thinking too much about what's being shown. That's an absolutely valid way to use the technology. If this approach works for you and doesn't get in your way, IntelliSense is doing exactly what it's designed to do. You can also employ IntelliSense more deliberately by using the shortcuts associated with displaying IntelliSense information.

You might want to turn statement completion and parameter information off if you find them distracting, in which case you'll need to use the shortcuts, named commands, or toolbar buttons associated with the various IntelliSense features to display this information. To turn off statement completion in the Code Editor, go to the Text Editor folder in the Options dialog box. Select the language you want to apply your changes to, or select All Languages if you want to apply your changes universally. Open the General page, and in the Statement Completion section clear Auto List Members check box. You can also toggle the Parameter Information setting from this page.

Note

You can increase the number of options returned in a member list by clearing Hide Advanced Members. Hide Advanced Members is the default setting for Visual Basic .NET, so you might be missing a number of possible completions if you leave that setting checked.

With statement completion turned on, IntelliSense presents you with information as soon as you type an operator as part of a statement. If you have statement completion turned off or if you want to display this information immediately, press Ctrl+J. The result is shown in Figure 3-16.


Figure 3-16. Forcing statement completion by pressing Ctrl+J



To select an entry to complete a statement, use the up and down arrow keys to navigate to the desired completion and then press Tab.

Note

In Visual Studio .NET 2003, you can set an option to make IntelliSense preselect the most frequently used member for a particular statement in Visual C#. You'll find this option on the Formatting page in the C# folder in the Options dialog box.

To force parameter information like that shown in Figure 3-17, press Ctrl+Shift+Spacebar. This gives you a list of the parameter overloads you can choose from for a particular method. With the parameter information showing, use your up and down arrow keys to view the available parameters.


Figure 3-17. Viewing the parameter information for a method by pressing Ctrl+Shift+Spacebar



Use the parameter information provided by selecting the item that best suits your needs and then type the parameters into your method. You'll notice that after you type each parameter, the next parameter in the list appears bold. Watching for this pattern helps ensure that every parameter in the list is entered correctly.

You might not be too familiar with the word completion feature if you're used to using IntelliSense automatically. Word completion lets you type in a few characters of a particular statement and get a list of possible completions for that statement. This functionality is a bit different from statement completion, which gives you a member list based on context. Word completion simply gives you a list of all the possible completions for the letters you've typed in. The shortcut for word completion is Alt+Right Arrow, but the statement completion shortcut (Ctrl+J) also works.

Finally, you might have noticed that when you hold your mouse pointer over an identifier in the Code Editor, ToolTip information appears. This ToolTip information is part of the Quick Info feature of IntelliSense, which contains the declaration for the identifier and any associated code comments. You can force this information using Ctrl+K, Ctrl+I. You can add code comments to any method in Visual C# by typing /// on the line directly above the method definition. Even if you're not going to create documentation for your methods, IntelliSense makes code comments such as these helpful for letting another developer figure out how to use your code.

Brace Matching


Automatic brace matching is an IntelliSense feature that helps you determine whether braces in your code are matched properly. Brace matching works in Visual C# and Visual C++ and goes into effect when you type a closing brace into the Code Editor. The brace types affected include parentheses (), brackets [], and braces {}. In addition, the conditional macro expressions #if, #else, and #endif are matched as you type the closing expression, and quotation marks are matched when you type the closing set.

You can't turn off brace matchingbut why would you want to? Well, you might want to, and we'll show you a way to at least hide this feature so it doesn't bother you while you're typing. To customize the way that braces are matched, go to the Fonts And Colors page in the Environment folder of the Options dialog box. Select Brace Matching from the Display Items list. If you clear the Bold check box for Brace Matching and leave the Foreground and Background settings as Automatic, you no longer see the matched braces when you type in the Code Editor. Of course, you can also change the colors and settings to make the brace matching stand out even more. Making the background Yellow while keeping the text Bold really makes the braces pop out (and is my preferred work setting).


Dynamic Help


Dynamic Help is one of those awesome features that's easy to overlook when you're working with a complex tool such as Visual Studio .NET. Dynamic Help is a tool window in the IDE that constantly serves up help suggestions based on what you're doing in the IDE. If you select a designer, you see suggestions for designer help. If you select a tool window, you see help for that particular tool window.

More important, Dynamic Help serves up information based on code context in the IDE. If you open a Visual C# Code Editor window and you type Console, you'll see a Dynamic Help window that looks like the one in Figure 3-18. This window provides links to the help topics appropriate to the System.Console class. This is extremely significant because I can't even begin to tell you how many times I've typed Ctrl+Alt+F3 (Help.Search) and then proceeded to type the same thing I've already typed into the Code Editor.


Figure 3-18. The Dynamic Help window



I think this feature isn't talked about more often because of limited space in the IDE. Developers need to use the Properties tool window frequently, so Dynamic Help gets left behind (literally). Using the appropriate shortcuts, you can change that a little bit and make it easier to use this window.

To bring up the Dynamic Help window, press Ctrl+F1. To get a feel for how this will work when you're using the IDE, open a project and be sure the Properties window is obscuring the Dynamic Help window. Navigate to someplace in one of the code files for the project and consider how you can get information about the different elements in your source file. You can place the cursor in a particular statement and press F1 to bring up the associated Help topic. You can press Ctrl+Alt+F3 to open the Search window and then type in the subject that you're looking for help on, or you can press Ctrl+F1 and choose from one of the suggestions from Dynamic Help. In my experience, the Dynamic Help window provides the information I'm looking for well over 90 percent of the time. Using this window takes a little practice, but when you get used to it you'll probably save a significant amount of time.


/ 118