C# 发送控件快捷方式
我正在用 c Sharp/xaml 编写一个程序。我有一个保存按钮,并且认为使其生效的最简单方法是在按下时如果我可以发送“control s”信号。执行此操作的命令是什么(以及任何包含 VS 不会添加为标准的命令)?
减少线程数量的一个完全不同的问题是,当您到达末尾时,如何使文本块(或文本框,如果更容易的话)自动换行,而不是继续将文本发送到屏幕外。
I am making a program in c sharp/xaml. I have a save button, and figured the easiest way to make it effective was when pressed if I could send the "control s" signal. What is the command (and any includes VS wouldn't add as standard) to do so?
A completely different question to cut down on thread count, how would I make a textblock (or textbox if easier) automatically newline when you reach the end rather than continuing to send text offscreen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在将 UI 与按键耦合之前,我建议您先研究一下更好的模式(例如 命令),但如果您确实想这样做,可以使用 SendKeys 类。这将允许您将按键发送到应用程序,就像用户按下这些键一样。
至于第二个问题,如果您使用 WPF,只需创建一个文本框元素并设置
AcceptsReturn="True"
和TextWrapping="Wrap"
。这是一个例子:There are better patterns that I would suggest looking into before coupling your UI to keypresses (such as Commands) but if you really want to do this, you can use the SendKeys class from windows forms. This will allow you to send key presses to the application as if the user pressed those keys.
As for the second question, if you're using WPF just create a textbox element and set
AcceptsReturn="True"
andTextWrapping="Wrap"
. Here's an example:您可以使用 SaveFileDialog() 。
You can use the SaveFileDialog() .
如果您使用 XAML,我会假设您使用 WPF。因此,您应该能够将按钮的
Command
属性绑定到ApplicationCommands.Save
。If you're using XAML I'll assume you're using WPF. So you should be able to bind the
Command
property of the Button toApplicationCommands.Save
.