文本框拖曳问题 [英] tow problems with textboxs

查看:94
本文介绍了文本框拖曳问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Developers,

我在下面的代码中包含两个带有小鸡按钮的文本框,我的观点是从textbox1中获取大于或小于7的数字范围,然后将其清除到textbox1中具有前面提到的范围的数字,然后将其放入textbox2中.
好吧,我有两个问题,第一个是当我单击按钮时,将那个范围放到textbox2上,但是没有从textbox1上删除它? ,另一种是当我输入很长的数字时,会出现一个错误,说(

Hi Developers,

i have this code below it contain two textbox with chick button and my point is to take the range of numbers from textbox1 that are over and below 7 and put it to the textbox2 with clearing the numbers from the textbox1 with that range that mention before.
well, i have two problems the first one is that when i click on the button it put that range at textbox2 but did''nt delete it from textbox1 ??? , the other one is that when i put a long range of number it appear an error which say (

Exception of type ''System.OutOfMemoryException'' was thrown



所以请多谢我






so please i will be thankful for any help




protected void Button1_Click(object sender, EventArgs e)
{

    string[] lines = TextBox1.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
    Int32 lineCount = lines.Length;
    Int32 i = 0;


    while (i < lineCount)
    {
        if (lines[i].Length != 7)
        {
            TextBox2.Text += TextBox2.Text + lines[i] + Environment.NewLine;

        }
       i = i + 1;

    }


}





最好的问候,
Ahmed





Best regards,
Ahmed

推荐答案

请在对问题的评论中看到我的问题.

该代码是足够糟糕的,并且极其无效.永远不要使用字符串连接,尤其是对于慢速属性TexBox.Text.除了一遍又一遍地读取和写入此属性的问题之外,您是否还理解字符串是不可变的?您是否还要说明由于这一事实而导致的重复级联("+")无效.在这种情况下,应始终使用可变类System.Text.StringBuilder,请参见 http://msdn. microsoft.com/en-us/library/system.text.stringbuilder.aspx [
是的,不会清除该文本框,因为您没有做任何事情来清除它. :-).

但是,我几乎不敢相信您的代码会导致此异常.问题可能出在其他地方.也许问题是多次重复执行此代码而不清除修改的文本框?那我就能理解了.请在调试器下进行检查.

—SA
Please see my questions in my comments to the question.

The code is bad enough and extremely ineffective. You should not use string concatenation, ever, especially with slow property TexBox.Text. In addition to the problem of reading and writing this property over and over, do you understand that strings are immutable? Do you have even to explain how ineffective is the repeated concatenation (''+'') due to this fact. You should always use mutable class System.Text.StringBuilder in such cases, see http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx[^].

You should calculate new text and assign it to TexBox.Text at once, for reasonable CPU and memory efficiency.

What else. The "while" loop is pointless, you can do it with "for" loop, hard-coding is bad (7?).

And yes, the text box is not cleared because you don''t do anything to clear it. :-).

Nevertheless, I hardly can believe you code causes this exception. The problem could be somewhere else. Maybe, the problem is repeating this code many times without cleaning the modifying text box? Then I could understand it. Please check up under debugger.

—SA


改为使用 StringBuilder ,然后将整个值分配给TextBox2.Text.
Int32的上限为2,147,483,648.请检查您的长度不能超过.
Use StringBuilder instead and then assign whole value to TextBox2.Text.
limit of Int32 is 2,147,483,648. please check your length must not be exceed.


这篇关于文本框拖曳问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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