にlabel
コントロールがありwindows form
ます。で全文表示したいlabel
。状態は次のようになります。
- テキストの長さが 32 文字を超えると、改行されます。
可能であれば、ハイフン (-) なしで完全な単語で分割します。
これまでのところ、以下のコードまで到達しています:
private void Form1_Load(object sender, EventArgs e) { string strtext = "This is a very long text. this will come in one line.This is a very long text. this will come in one line."; if (strtext.Length > 32) { IEnumerable<string> strEnum = Split(strtext, 32); label1.Text =string.Join("-\n", strEnum); } } static IEnumerable<string> Split(string str, int chunkSize) { return Enumerable.Range(0, str.Length / chunkSize) .Select(i => str.Substring(i * chunkSize, chunkSize)); }
しかし、問題は、32 文字で分割されているため、最後の行が完全に表示されないことです。
これを達成する別の方法はありますか?