如何在多行文本框中创建命令行
我正在使用一些使用 GPIB 的电子仪器。我可以像这样与仪器进行通信:
K2400.WriteString("*IDN?", true);
textBoxK2400.Text += K2400.ReadString() + Environment.NewLine;
第一行将执行命令,在第二行中我将最后一个命令的响应添加到文本框。如何直接在文本框中写入命令并添加响应?
例如,如果用户命令在“>>”等指示符之后输入然后按 ENTER 键,响应应添加到文本框的下一行。
那么如何读取文本框的最后一行并将响应添加到新行中呢?我正在寻找类似的方法:
private void Execute(string command)
{
K2400.WriteString(command, true);
textBoxK2400.Text += K2400.ReadString() + Environment.NewLine;
}
I am working with some electronics instruments using GPIB. I can communicate with instruments like this:
K2400.WriteString("*IDN?", true);
textBoxK2400.Text += K2400.ReadString() + Environment.NewLine;
The first line will execute a command, and in the second line I add the response of the last command to the textbox. How can I write the command in the textbox directly and add the response?
For example, if the user command entered after an indicator like ">>" and hitting ENTER, the response should be added in the next line of textbox.
So how can I read the last line of a textbox and add the respone in a new line? I am looking for a method like:
private void Execute(string command)
{
K2400.WriteString(command, true);
textBoxK2400.Text += K2400.ReadString() + Environment.NewLine;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用两个文本框(文本框和列表框可能更好),但使它们看起来像“一个”文本框。如果使用 WPF,它看起来会非常漂亮,并且至少可以采用 Windows 形式。
做了一个快速测试..
并使用文本框的 KeyPress 事件的代码:
Use two Text boxes(textbox and a listbox might be better) but make them look as "one" textbox.. If using WPF it could look pretty nice and in Windows form possible at least.
Did a quick test..
And with this code for KeyPress event for the textbox:
你可以试试这个:
You could try this:
这样。我只是建议“缓冲”文本的一部分,而不是全部,因为到最后它可能会很长。您可以将其拆分为前面的行并获取多行(即 10 行)。
并且不要忘记将字段设置为黑色,文本设置为绿色,当命令字段这样装饰时看起来更专业。
this is it. I'd just recommend to 'buffer' a part of the text, not all, because it could be long by the end. You can split it to lines before and take a number of lines (i. e. 10).
And don't forget to make the field black and the text green, it looks much more professional when the command field is decorated such way.
首先我建议使用 RichTextBox。
要捕获 ENTER 您应该使用 KeyPress Event 。
Well first i would suggest a RichTextBox to use.
To capture ENTER you should use KeyPress Event .