Windows Forms の TextBox へクリップボードから貼り付ける際、改行コードが CR+LF でないと改行が表示されません。
貼り付け時に改行コードを調整して対処しました。
public class MyTextBox : TextBox
{
public static string NormalizeNewLine(string s)
{
return s.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
}
protected override void WndProc(ref Message m)
{
const int WM_PASTE = 0x302;
if (m.Msg == WM_PASTE)
{
try
{
var t = Clipboard.GetText();
Paste(NormalizeNewLine(t));
return;
}
catch { }
}
base.WndProc(ref m);
}
}
参考