private void CopySelection() { if (Lines.Count > 0) { StringBuilder SelectedText = new StringBuilder(); if (Selection == null || Selection.IsEmpty()) { foreach (string Line in Lines) { SelectedText.Append(Line); } } else { for (int LineIdx = Math.Min(Selection.Start.LineIdx, Selection.End.LineIdx); LineIdx <= Math.Max(Selection.Start.LineIdx, Selection.End.LineIdx); LineIdx++) { int MinIdx, MaxIdx; ClipSelectionToLine(LineIdx, out MinIdx, out MaxIdx); SelectedText.Append(Lines[LineIdx], MinIdx, MaxIdx - MinIdx); } } Clipboard.SetText(SelectedText.ToString().Replace("\n", "\r\n")); } }