Clipboard 或 SendKeys 类与 WinForms 有什么关系?

发布于 2024-08-08 23:18:55 字数 105 浏览 7 评论 0原文

这两个有用的类都在 System.Windows.Forms 参考下...

我看不出它们和 winforms 之间有多大关系..有人知道它们为什么在那里吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

Saygoodbye 2024-08-15 23:18:55

它们在内部使用 Win32 平台 API,WinForm 是在该 API 上构建的。

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

眼藏柔 2024-08-15 23:18:55

Windows 窗体在创建时是在桌面上创建图形用户界面的唯一(微软)方法。

SendKeys 和剪贴板都使用 Windows API 来操作 GUI 应用程序。当它被创建时,可以合理地假设它们将在 GUI 程序中使用,这(当时)意味着 Windows 窗体应用程序。

这些通常都不会从控制台应用程序中使用,但如果您这样做,包括“窗口”程序集(当时意味着窗口窗体)是合理的事情,因为您正在使用视窗系统。

不过,我确实同意,现在 WPF 已经存在,将它们放在单独的程序集中会更好。然而,微软非常擅长保持向后兼容性。

为此,他们将其保留在 Windows 窗体命名空间中,但也实现了 System.Windows.Clipboard 用于 WPF 应用程序。 (我相信他们认为现代开发中不需要 SendKeys,因为它有点被滥用,并且只是在设计上将其排除在外。)

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.)

甩你一脸翔 2024-08-15 23:18:55

一般来说,您不会将 Clipboard 或 SendKeys 与 ASP.Net 应用程序或控制台应用程序一起使用,因此将它们放在 System.Windows.Forms 中是完全有意义的。

您希望他们在哪里?在 System.ClipboardAndSendKeys 中?

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?

回梦 2024-08-15 23:18:55

SendKeys 可以方便地突出显示文本框。 SendKeys“{HOME}+{END}”是文本框获得焦点后从 Visual Basic 继承的典型技术。

Clipboard 类很有用,因为它允许您获取存储在计算机剪贴板上的数据,如果数据来自正在运行的另一个应用程序,则尤其有用。剪贴板是几乎所有具有复制/粘贴语义的应用程序中的预期行为。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文