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 was looking at the documentation for the Form.Dispose method and found the following statement: “Dispose will be called automatically if the form is shown using the Show method. If another method such as ShowDialog is used, or the form is never shown at all, you must call Dispose yourself within your application.”

This is a surprise to me. I had always been led to believe that Dispose is always called for a Form. It looks like if I don’t call Dispose after displaying a modal dialog, there will be a resource leak. Is the documentation wrong, or if not, can you please explain this behavior?

- Befuddled in Bellingham

Dear Befuddled,

In this case the documentation is correct, although apparently well-hidden. It is a best practice to call Dispose on modal forms when you are done with them.

Forms and the controls within them use unmanaged resources such as window handles which are a limited system resource. The garbage collector is good at cleaning up memory but not so good at cleaning up resources such as handles that are more precious than memory.

Modal forms were designed so that you could access state information such as text in a textbox or a dialog result after the form has closed. If Dispose was called automatically, there is no guarantee that the information will still be there when you try to access it.

- Doc D

Dear Doc Detective,

I’m trying to return a machine’s IP address, and I can’t seem to get it right. Every example I see uses code such as the following:

System.Net.Dns.GetHostEntry(My.Computer.Name).
 AddressList(0).ToString()

I’ve tried this, but the string I get back is something like “fe80::85f3:3dc2:42e6:eaa5%8”. The actual IP address isn’t returned until I reach the .AddressList(2) or .AddressList(3) element. What’s up with that?

- Listless in Livonia

Dear Listless,

The AddressList array can contain a different number of elements depending on factors such as whether the machine has multiple network cards or is using IP Version 4 or IP Version 6. It sounds like you are looking for the IP 4 address-you can get this by looping through the AddressList array and checking the AddressFamily value:

For Each ip In System.Net.Dns.GetHostEntry(
System.Net.Dns.GetHostName).AddressList
   If ip.AddressFamily =
   Net.Sockets.AddressFamily.InterNetwork Then
      'only IP4
      Me.ComboBox1.Items.Add(ip)
   End If
Next

In this example, the AddressFamily enumeration InterNetwork represents the IP Version 4 address, as noted in the topic “AddressFamily Enumeration”. Try this, and you should get the right IP address.

- Doc Detective

Dear Doc Detective,

I’m a long-time Visual Basic programmer just getting started with Silverlight. When I try to reference the My namespace in a Silverlight app, I keep getting errors. Is the My namespace supported in Silverlight?

- Mystified in Mystic

Dear Mystified,

The My namespace which Visual Basic programmers have come to know and love is not supported in Silverlight. This is noted in the topic “Visual Basic Run-Time Support in Silverlight”.

What isn’t noted in the topic is the reason why. Silverlight apps run in a “sandbox” environment and are prevented from accessing local resources. Since most of the functions in the My namespace involve accessing local resources, and since Silverlight wanted to keep it’s runtime small... well, you get the picture. Hope that solves the mystery.

- The Doc

Dear Doc Detective,

I have a Label control of a fixed size. When we localize the application into other languages, the localized string is sometimes too long for the allotted space.

Our solution is to use the GetPreferredSize method to determine the length of the string, then add a “...” on the end of the string and display the full string in a ToolTip. I can’t figure out how do get just the displayed portion of the string and append the “..." onto it. Any ideas?

- Strung Out in Stroudsburg

Dear Strung,

Sometimes the answer is staring you right in the face. The Label control has a AutoEllipsis property that does exactly what you are looking for. Just set it to true and you’re done-isn’t it nice when you don’t have to write code?

- Doctor D

Doc’s Doc Tip of the Day

Every issue the Doc has admonished you to send your feedback on documentation that is incorrect or isn’t helpful. Ever wonder what happens when you actually do send feedback?

Every single comment that you send in, whether via the local or online links, is reviewed and passed on to the appropriate writer. Writers are responsible for following up on these and determining if the topic does indeed need to be fixed; in many cases they may contact you to get clarification.

Last year the process resulted in over 1500 topics that were corrected or improved based on your feedback. Once a topic has been updated, a “change table” entry is added to the bottom of the topic with “customer feedback” listed as the reason for the change.

I’ve said it before and I’ll say it again: 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/aw58wzka.aspx

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.addressfamily.aspx

http://msdn.microsoft.com/en-us/library/system.net.sockets.addressfamily.aspx

http://msdn.microsoft.com/en-us/library/bb404714(VS.95).aspx

http://msdn.microsoft.com/en-us/library/system.windows.forms.label.autoellipsis.aspx