Finding what you need in the Microsoft® Visual Studio® 2008 documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.
Can’t find what you’re looking for? Just ask-if it’s in there, I’ll find it for you; if it isn’t, I’ll let you know that as well (and tell you where else you might go to find it).
Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.
Dear Doc Detective,
I have the following problem in Visual Studio 2008: I have created a form, added a ToolStrip control, and to that ToolStrip I have added a ToolStripComboBox.
In the form Load event I have added the following code:
ToolStripComboBox1.ComboBox.Focus()
I have also added the same code in the form Activated event.
When the form loads, the ComboBox does not get the focus. If I minimize the form and restore it then it does get the focus. What can I do to set the focus after loading?
-Puzzled in Puyallup
Dear Puzzled,
It is a common misconception that the Focus method should be used to set the focus to a particular control. In the topic Control.Focus Method, the fine print states that “Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.”
In your case, calling the Select method in the Form1_Activated event should solve your problem. Perfectly logical, right?
-Doc D
Dear Doc Detective,
I apologize if this is a frequently asked question, but is there a command-line scriptable equivalent of Visual Studio 2008’s Publish Wizard? I need to test ClickOnce deployment of a WPF app, and my automated build process occurs nightly. I would like to be able to script all the steps in the publication process without requiring any UI interaction, automated or otherwise. Can you help?
-Clickless in Cleveland
Dear Clickless,
As someone once told me, “Of course I canhelp; the question is, will I?" If you are using MSBuild, you can use the /target:publish command to build a ClickOnce application from the command line. An example:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild
.exe /target:publish /p:Configuration=Release
“YourProjectOrSOlutionNameHere”
This is described in the topic “Building ClickOnce Applications from the Command Line”. If you are using an MSBuild script you can also try a SOLUTIONTOPUBLISH node instead of SOLUTIONTOBUILD.
-Doc Detective
Dear Doc Detective,
Is there some standard windows algorithm or standard for placing popup dialogs? And if so, is this standard implemented within WinForms?
I’ve heard all sorts of conflicting things about what the standard is or should be-place popups in the center of the owning dialog, remember the last place the user placed it, etc. All the while I’m thinking that surely the designers of WinForms know what the standard is and have a way to make it easy for me to conform to it. For all I know, maybe I’m already conforming, simply owing to the fact that I haven’t been doing anything with the dialog’s coordinates.
I’m hardly a UI geek, and I’m sure that this topic is covered by all the better books on the subject, but I haven’t managed to find a MSDN resource that goes directly at this topic. Probably just due to me not knowing the right keyword to search for. Can I get a pointer please?
-Placated in Placerville
Dear Placated,
You would think that there would be a standard for this, but it seems it is a matter of personal opinion amongst UI geeks. I would recommend following the lead of the designers Windows Forms-when you call the MessageBox.Show method, the resulting popup is centered on the screen.
When creating your own popup dialogs, you can duplicate this behavior by setting the FormStartPosition enumeration to CenterScreen. This is described in the topic “FormStartPosition Enumeration”.
On the other hand, if a modal popup is specific to another form, you might want to set the FormStartPosition enumeration to CenterParent. In this case, you would want to pass in an owner in the overload for the ShowDialog() method-the owner is the parent window that is always behind your modal dialog. If you don’t specify one, one will be calculated for you.
-The Doc
Dear Doc Detective,
In your reply to Fuming in Fullerton in the Jan/Feb 2009 issue of CoDe Magazine, you asked why anyone would want to cut or copy a blank line. If that was what the “Apply Cut or Copy commands when there is no selection” option was for, I’d agree that it was silly. However, I can’t even begin to tell you how many times I use ctrl-c to copy, and ctrl-x to cut, whatever line the cursor is on without needing to select the whole line.
-Cutting in Cupertino
Dear Cutting,
Interesting-the Doc didn’t know that you can use ctrl-c and ctrl-x without selecting text. This feature is actually mentioned in the same “How to: Set General Editor Options” that I mentioned in my reply-I guess I should have read it more carefully.
The option setting, however, has no effect on your ability to copy and cut without selecting. I just tested this, and ctrl-c and ctrl-x on a line of code appears to work regardless of the “Apply Cut or Copy commands when there is no selection” setting. The option simply turns off the copy and cut on a blank line to prevent overwriting the clipboard.
I guess the option makes sense if you want to use ctrl-c and ctrl-x to clear the clipboard, but it still seems odd that this option is on by default.
- Doctor D
Doc’s Doc Tip of the Day
The Doc frequently hears from readers that what they want most from the documentation is code examples, and that it isn’t easy finding them even when they do exist. Ever wish that you could enter a property or method name and just find the topics that contain code?
Now you can, thanks to the new MSDN Code Search Preview in the MSDN online library. Code Search allows you to enter a keyword, specify a language and other parameters, and quickly return all topics that contain code that uses that keyword.
For example, entering FormStartPosition and specifying VB .NET as the language returns 51 topics with code that demonstrates the use of the enumeration. Even better, the code itself is displayed in the search results, so you don’t need to open each topic to see if it’s what you want.
You can check out the MSDN Code Search Preview at http://msdn.krugle.com.
Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it by clicking on the “Send feedback” link in local Help topics, or the “Click to rate and give feedback” link in online Help.
URLs
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus.aspx
http://msdn.microsoft.com/en-us/library/7wt11hea.aspx
http://msdn.microsoft.com/en-us/library/ms165431.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.formstartposition.aspx
http://msdn.microsoft.com/en-us/library/w61zzfwe.aspx