简体   繁体   English

按键事件并删除文本框和RichTextBox中的文本

[英]Keypress event & delete text in textbox & richtextbox

Been trying to solve this problem for hours now, and its frustrating me, hope anyone here can help me! 数小时以来一直在努力解决这个问题,这让我感到沮丧,希望这里的任何人都可以帮助我!

What im trying to do, is that i want the textbox to clear the text after i have searched for the word i have entered, and the richtextbox to delete whatever is in it when im searching for a new word. 我想做的是,我希望在搜索输入的单词后,文本框清除文本,并让richtextbox在搜索新单词时删除其中的内容。

       private void button1_Click(object sender, EventArgs e)
    {   

        string downloadedString;
        System.Net.WebClient client;

        string playerName = this.inputText.Text;
        client = new System.Net.WebClient();

        downloadedString = client.DownloadString("http:randomaddress;
        string[] stringSeperator = new string[] { "\n" };
        string[] result;

        result = downloadedString.Split(stringSeperator, StringSplitOptions.None);
        foreach (string s in result)
        {
            Bunch of if statements
        }
    public void SortString(string s)
    {
        //string manipulation
        richTextBox1.Text += manipulate2 + "--" + " ";
    }
    public void SortString2(string s)
    {
        //string manipulation
        richTextBox1.Text += manipulate2 + "--" + " ";
    }
    public void SortString3(string s)
    {
        //string manipulation
        richTextBox1.Text += manipulate2 + "--" + " ";
    }

         private void richTextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }


    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void True(object sender, PreviewKeyDownEventArgs e)
    {

    }

Been trying many different approaches but i just cant make it to work.. But to say again what it is what i want.. textbox is used for search, the input i get from the search gets showed in the richtextbox. 一直在尝试许多不同的方法,但我只是无法使其工作..但要再次说一下我想要的是什么。.文本框用于搜索,我从搜索中获得的输入将显示在richtextbox中。 The search word should be cleared after i have entered the word and searched for it, and the richtextbox needs to clear the former search everytime i search again. 输入单词并进行搜索后,应清除搜索词,并且每次我再次搜索时,richtextbox需要清除以前的搜索。

I suppose this is very simple, but havent worked with GUI for more than 2-3 days, used to console :) 我想这很简单,但是还没有使用GUI超过2-3天,用于控制台:)

Thank you in advance! 先感谢您!

Oh and btw, everything else works like it should if that wasnt clear! 哦,顺便说一句,如果还不清楚的话,其他一切都会正常工作!

Ok...just Clear() them both after you have retrieved the search value? 好的...在检索到搜索值之后,只需将它们清除()即可?

string playerName = this.inputText.Text;
this.inputText.Clear();
richTextBox1.Clear();
// ... rest of your code ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM