Finding what you need in the Microsoft® Visual Studio® 2005 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’m having a problem with the DoubleClick event for a Button control. I’ve added code in the DoubleClick event handler, but at run time the event never gets fired. Any idea what’s going on here?

- Misfired in Mississippi

Dear Misfired,

By default the DoubleClick event for a Button isn’t raised. Although I can’t find this documented anywhere it makes sense-users don’t normally think of double-clicking a button; they expect a single click to work. If, however, you really need to enable double-clicking, you can create your own custom button that inherits from the Button class.

You can use the Control.SetStyle method to override the default behavior of the ControlStyles.StandardDoubleClick property like this:

Public Class DoubleClickButton
        Inherits Button
        Sub New()
            MyBase.New()
Me.SetStyle(ControlStyles.StandardDoubleClick,_
                                          True)
Me.SetStyle(ControlStyles.StandardClick, True)
            Me.UpdateStyles()
        End Sub

Note that you can’t put code in both the Click and the DoubleClick event; the code in the Click will always execute and the DoubleClick event still won’t get raised.

You can learn more about the ControlStyles method by looking at the “ControlStyles Enumeration” topic in the MSDN Library.

- Doc D

Dear Doc Detective,

I’ve created a User control inside my Windows Application project (from the Project menu, choose Add User Control) but I can’t see my control in the Toolbox, nor can I see any way to add it.

If I instead create a User control via a Windows Control Library project it automatically shows up in the Toolbox, but I don’t want a separate project for my control. Why is there an option to add a User control to a project if there is no way to use it?

--Useless in Utah

Dear Useless,

This is indeed a strange one-everything that I was able to find states that User controls should automatically be added to the Toolbox regardless of whether they are in your project or in a separate project. There is one possibility though-there is an obscure setting that allows you to turn off this feature (although I don’t really know why anyone would).

From the Tools menu, select Options, select Windows Forms then click the General tab. Scroll to the bottom and check the AutoToolboxPopulate property-if it’s set to False, you’ve found your problem. This option is described in the topic “General, Windows Forms Designer, Options Dialog Box.”

You didn’t say which language you are using, but that could also be the source of your problem. When you first installed Visual Studio you were asked to select a language profile-if you chose C++, the AutoToolboxPopulate property is set to False; for any other language profile it’s set to True. Go figure!

- Doctor D

Dear Doc Detective,

I see that Visual Basic 2005 has a TextBoxArray component that can be added to the Toolbox. Unfortunately, I haven’t been able to figure out how to use this component. I drag it out of the Toolbox onto my form and it just sits there in the component tray.

I have a form with 27 TextBox controls and I need a way to programmatically go through all of them and set some properties. I’d appreciate some assistance on how to use this component to create an array of textboxes.

- Arrayless in Arizona

Dear Arrayless,

The TextBoxArray component is a part of the Microsoft.VisualBasic.Compatibility namespace; it’s primarily there for use by the upgrade tool when upgrading Visual Basic 6 applications that contained control arrays. While there is no reason that you can’t use the components and functions in this namespace, they aren’t documented so you are on your own.

In general though, you are better off learning the “.NET” way of programming rather than using these upgrade helper functions. While Visual Basic 2005 doesn’t support control arrays, you can use the Controls collection for your form to iterate through the TextBox controls and set properties; you can also use shared event handlers to emulate the way control arrays were handled in VB 6.

The following shows how you might do this:

' Visual Basic 2005
Private Sub ClearText(ByVal container As _
  Control)
    Dim ctrl As Control
    For Each ctrl In container.Controls
        If TypeOf (ctrl) Is TextBox Then
            ctrl.Text = ""
        End If
        If ctrl.HasChildren Then
            ClearText(ctrl)
        End If
    Next
End Sub

The topic “Control Arrays for Visual Basic 6.0 Users” contains examples of both this and using shared event handlers. If you really insist on doing control arrays the Visual Basic 6 way, you could upgrade a VB 6 project that uses a TextBox array and look at the code generated by the upgrade tool-but why?

- the Doc

Dear Doc Detective,

After working with Visual Studio 2005 for quite some time now, I’ve been tasked with modifying a Visual Basic 6 application. I’ve gotten used to many of the functions in the .NET Framework, and to say the least, going back to Visual Basic 6 is painful. Is there any way I can get the best of both worlds?

- Flustered in Florida

Dear Flustered,

It’s a little known fact that you can actually use much of the .NET Framework from Visual Basic 6 by using COM wrappers. The recently published article “Access the File System with .NET Framework Classes from Visual Basic 6” describes how to use several file system classes and demonstrates how you can do the same with most .NET Framework classes.

- the Doc

Doc’s Doc Tip of the Day

In the past, when you pressed F1 on a dialog box, error message, or other user interface, Help displayed a single topic. If this topic did not contain the information you needed, you then used the index or contents windows to locate additional topics, or searched for the appropriate information.

You can now access alternative Help topics that contain related information directly from the initial F1 topic displayed for the user interface. This feature is available for both local and online Help sources.

To view alternative F1 Help topics:

Press F1.

In the F1 Options drop-down list located at the top of the returned topic, select one of the topics listed -or- In the F1 Options drop-down list, select Go to Search to display the Search Page.

Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it at vsdocs@microsoft.com.

URLs

http://msdn2.microsoft.com/en-us/library/system.windows.forms.controlstyles(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/5aazxs78(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/kxt4418a.aspx

http://msdn.microsoft.com/vbrun/default.aspx?pull=/library/en-us/dnvs05/html/VBFusionIO.asp