日期:2014-05-20  浏览次数:20703 次

模拟内存分配
我想计算text_content 中输入内容的 字符的长度 就是字节:一个汉字是两个字节 一个字母是一个字节 数字也是一个字节
在窗体中已经有64个button 每个button代表一个64个字节

想实现的是:输入的内容若为空 没有按钮变绿 
  若有输入 则有一个bottom变绿  
  输入内容大小超过64B 则再亮一个botton
  若删除字符 相应的按钮颜色也根据大小变化

C# code
 private void text_content_TextChanged(object sender, EventArgs e)
        {
            
            int count=Encoding.Unicode.GetByteCount(text_content.Text)/ 64;
           Convert.ToInt32( textBox_charnumber.Text =count);//如何在textBox_charnumber.Text 显示输入内容的字节大小?
            for (int i = 0; i < count; i++)
            {
                btn[i].BackColor = Color.Green;
            }
        }


------解决方案--------------------
textBox_charnumber.Text=Encoding.Unicode.GetByteCount(text_content.Text).ToString()