VB.net テキストボックスをバイト数制限をかける

2017年3月29日水曜日

VBプログラミング

t f B! P L
すごいシンプルに。

textBox1で20バイトの制限をかけるとなるとこう↓

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(Me.TextBox1.Text) > 20 Then
            Me.TextBox1.Text = Me.TextBox1.Text.Remove(Me.TextBox1.Text.Length - 1)
            Me.TextBox1.SelectionStart = Me.TextBox1.TextLength
        End If
    End Sub

あまりにもシンプルにしすぎていろいろと対応できないコードになってる。

一応、うごく。不具合の可能性が高いけど。

検索

年月ごとアーカイブ

フレンドブログ

Translate

自己紹介

自分の写真
映画が好き! 音楽好き! 演奏も好き! ミキシングが一番好き!

QooQ