• 0

[VB.NET] Clipboard


Question

For some reason this is not copying to the clipboard, can someone tell be why?

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

Clipboard.SetDataObject(Net.Dns.GetHostByName(Net.Dns.GetHostByName("localhost").HostName).AddressList(0), True)

End Sub

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Does it throw an exception? Or are you unable to get the data back out?

I just tried that and it works for me. The Clipboard will store the IPAddress as an IDataObject. You'll have to use the GetDataObject method to get the IDataObject back, then the GetData method from the IDataObject to get the IPAddress, casting appropriately.

Link to comment
Share on other sites

  • 0

I just tryed haveng something on the clipboard, then doing that code, it empties the clipboard, but doesnt put the info on it that i want

Link to comment
Share on other sites

  • 0

You need to ToString it:

Clipboard.SetDataObject((System.Net.Dns.GetHostByName(System.Net.Dns.GetHostByName("localhost").HostName).AddressList)[0].ToString(), true);

I did it in C# though, probably the only difference is the array indexing style.

Link to comment
Share on other sites

  • 0
is there a "tostring" you can attach to the end of that?

Everything in .NET has a ToString method :yes: At a minimum, it's inherited from System.Object and I believe it returns a string that says what type it is, ie. "System.Object". You can override this in your own classes though to have it return something descriptive to that instance (Y)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.