private void menuSelectAll_Click(object sender, EventArgs e) { DoInActiveTextBox(ctrl => { if (ctrl.SelectionLength == ctrl.Text.Length) { // テキストボックスの文字列全選択を解除する ctrl.SelectionLength = 0; } else { // それ以外のときはテキストの前選択をおこなう ctrl.SelectAll(); } }); }