anhoppe
anhoppe

Reputation: 4507

What is the purpose of each of the two Clipboard classes in .NET?

Why does .NET provide two Clipboard classes:

System.Windows.Clipboard and System.Windows.Forms.Clipboard?

Is there a significant difference between those classes?

Upvotes: 0

Views: 124

Answers (2)

Matt Burland
Matt Burland

Reputation: 45155

One is WPF and the other is Windows Forms. If you look at the MSDN pages, you'll see that System.Windows.Clipboard is in the PresentationCore.dll assembly (that's WPF), the other System.Windows.Forms.Clipboard is in the System.Windows.Forms.dll assembly (that's, not surprisingly, windows forms).

They are both, essentially, just static wrappers around calls to the windows API (in user32.dll) to manipulate the clipboard. Use which ever one matches the technology you are using for your application. This avoids the need to import System.Windows.Forms into your WPF application just for the clipboard or else re-writing a bunch of pinvoke code to hit the API directly in your own code.

Upvotes: 2

vcsjones
vcsjones

Reputation: 141678

System.Windows.Clipboard is used by WPF applications, whereas System.Windows.Forms.Clipboard is used for WinForms.

They do the same thing, it's just there twice so WPF applications don't need to add a reference to System.Windows.Forms, and vice versa.

Secondly, System.Windows.Clipboard came after System.Windows.Forms.Clipboard. System.Windows.Clipboard exists for other platforms that can't reference System.Windows.Forms, like Silverlight.

Upvotes: 4

Related Questions