文本框的内容和外部应用程序的按钮 [英] Contents of textbox and button to external application

查看:61
本文介绍了文本框的内容和外部应用程序的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#(visual studio)制作一个应用程序,以便在游戏中与rust的控制台进行交互。我做了几个按钮,发送按键生锈。虽然现在我希望能够制作文本框并存储内容并将其添加到随按钮发送的击键中。另外,如果我能做到这一点,我可以按下文本框中的输入或按​​下按钮执行它们两个都很好。



我的问题是有人可以点我正朝着正确的方向或向我展示能够实现这一目标的代码吗?

I am using C# (visual studio)to make an application to interact with the rust's console in-game. I have made a few buttons which sends keystrokes to rust. Although now I want to be able to make a textbox and store the contents and add it to the keystrokes that are sent with the buttons. Also if I could make it so I could just press enter in the textbox or press the button to execute them both that would be nice.

My question is can someone point me in the right direction or show me code that would accomplish this?

推荐答案

这里是我希望你会发现有用的示例代码:



'TextBox有一个用于KeyDown事件的EventHandler,如果按Enter键,则按代码单击按钮。
Here's sample code that I hope you'll find useful:

The 'TextBox has an EventHandler for the KeyDown Event, and if Enter is pressed, then the Button is clicked by code.
private string alwaysSendToRust = "hello Rust: ";

private void btnMessageToRust_Click(object sender, EventArgs e)
{
    // for testing only ...
    Console.WriteLine(alwaysSendToRust + tbxForRust.Text);

    // at this point call your method that
    // sends the string to Rust
    // messageToRust(alwaysSendToRust + tbxForRust.Text)
}

private void tbxForRust_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        btnMessageToRust.PerformClick();
    }
}


这篇关于文本框的内容和外部应用程序的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆