SMS TextLength 비교
SMS 입력받고 데이타 길이 체크하는 처리부분.
public partial class Form1 : Form
{
bool char_ASCIICODE = false;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
int length = Encoding.Default.GetBytes(this.textBox1.Text).Length;
if (length > 80)
{
this.textBox1.Text = this.textBox1.Text.Substring(0, this.textBox1.TextLength - (char_ASCIICODE ? 1 : 2));
char_ASCIICODE = false;
this.textBox1.Select(this.textBox1.TextLength, 0);
return;
}
length = Encoding.Default.GetBytes(this.textBox1.Text).Length;
this.label1.Text = string.Format("{0}/80", length);
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar < 256)
char_ASCIICODE = true;
else
char_ASCIICODE = true;
}
}
그리 어려운 코드가 아니라 주석도 없다!