views:

194

answers:

4

Those two useful classes are both under the System.Windows.Forms reference....

I can't see much relation between those and winforms.. Does anybody know why they're there?

thanks.

A: 

SendKeys can be handy for highlighting of textboxes. SendKeys "{HOME}+{END}" is a typical technique carried over from Visual Basic once a textbox has focus.

The Clipboard class is useful because it allows you to get data stored on a machine's clipboard, especially useful if it's data that comes from another application running. The clipboard is expected behavior in almost all applications that have any copy/paste semantic.

David in Dakota
=\ so what? it still can be useful in windows service, console, WPF......
Itay
re: selecting the text of a textbox:http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.selectall.aspxAlso, I see no reason why a "clipboard" wouldn't be useful in, say, a Console app.
theraccoonbear
I thought once defined the use is self explanatory. By the way, a windows service wouldn't be done in a windows forms project and it's doubtful you'd need a reference to the namespace.
David in Dakota
+3  A: 

They internally use Win32 platform APIs, on which WinForm was built.

Codism
they still could be in other dll....
Itay
But mainly in user32.dll.
Codism
+1  A: 

Windows Forms was, when it was made, the ONLY (Microsoft) means of creating a graphical user interface on the desktop.

SendKeys and the Clipboard are both using the Windows API in order to manipulate GUI applications. When this was created, it was reasonable to assume that these would be used from within a GUI program, which (then) meant a Windows Forms application.

Neither of these would typically be used from a Console application, but if you were doing so, including the "windowing" assemblies (which, at the time, meant windows forms) was a reasonable thing to do, since you're working with the Windowing system.

I do agree, though, that now that WPF exists, it would be nicer to have these in a separate assembly. However, Microsoft is very good about maintaining backwards compatibility.

To this end, they left this in the Windows Forms namespaces, but also implemented System.Windows.Clipboard for WPF applications. (I believe they decided that SendKeys was not required in modern development, since it's kind of abused, and just left it out by design.)

Reed Copsey
A: 

Generally speaking, you would not use Clipboard or SendKeys with an ASP.Net application or a console application, so it makes total sense for them to be in System.Windows.Forms.

Where would you expect them to be? In System.ClipboardAndSendKeys?

MusiGenesis