RickZeeland
Я могу порекомендовать вам Быстрое Цветное Текстовое Поле в которой есть много интересных вариантов, включая возможность копирования и режим схемы документа : Быстрое цветное текстовое поле для подсветки синтаксиса[^]
Вы можете использовать классы из "DiffMergeSample", например, с двумя элементами управления FastColoredTextBox в форме:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace TestDiff
{
/// <summary>
/// Show a form which compares two files set in the properties <see cref="FirstFile"/> and <see cref="SecondFile"/>.
/// Modified version of the FastColoredTextBox "DiffMergeSample" by Pavel Torgashov.
/// http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
/// </summary>
public partial class FormCompare : Form
{
int updating;
Style greenStyle;
Style redStyle;
/// <summary>
/// Initializes a new instance of the <see cref="FormCompare"/> class.
/// The properties <see cref="FirstFile"/> and <see cref="SecondFile"/> must be set first.
/// </summary>
public FormCompare()
{
InitializeComponent();
greenStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Lime)));
redStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(50, Color.Red)));
}
public string FirstFile { get; set; }
public string SecondFile { get; set; }
private void FormCompare_Shown(object sender, EventArgs e)
{
this.CompareFiles();
}
/// <summary>
/// Synchronize scrolling.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The event arguments.</param>
void tb_VisibleRangeChanged(object sender, EventArgs e)
{
if (updating > 0)
return;
var vPos = (sender as FastColoredTextBox).VerticalScroll.Value;
var curLine = (sender as FastColoredTextBox).Selection.Start.iLine;
if (sender == fctb2)
UpdateScroll(fctb1, vPos, curLine);
else
UpdateScroll(fctb2, vPos, curLine);
fctb1.Refresh();
fctb2.Refresh();
}
void UpdateScroll(FastColoredTextBox tb, int vPos, int curLine)
{
if (updating > 0)
return;
//
BeginUpdate();
//
if (vPos <= tb.VerticalScroll.Maximum)
{
tb.VerticalScroll.Value = vPos;
tb.UpdateScrollbars();
}
if (curLine < tb.LinesCount)
tb.Selection = new Range(tb, 0, curLine, 0, curLine);
//
EndUpdate();
}
private void EndUpdate()
{
updating--;
}
private void BeginUpdate()
{
updating++;
}
/// <summary>
/// Compare the files set in the properties <see cref="FirstFile"/> and <see cref="SecondFile"/>.
/// </summary>
private void CompareFiles()
{
if (!File.Exists(FirstFile) || !File.Exists(SecondFile))
{
MessageBox.Show(this, "Please select a valid file", "Invalid file");
return;
}
fctb1.Clear();
fctb2.Clear();
Cursor = Cursors.WaitCursor;
if (Path.GetExtension(FirstFile).ToLower() == ".cs")
fctb1.Language = fctb2.Language = Language.CSharp;
else if (Path.GetExtension(FirstFile).ToLower() == ".xml")
fctb1.Language = fctb2.Language = Language.XML;
else
fctb1.Language = fctb2.Language = Language.Custom;
var source1 = Lines.Load(FirstFile);
var source2 = Lines.Load(SecondFile);
source1.Merge(source2);
BeginUpdate();
Process(source1);
EndUpdate();
Cursor = Cursors.Default;
}
private void Process(Lines lines)
{
foreach (var line in lines)
{
switch (line.state)
{
case DiffType.None:
fctb1.AppendText(line.line + Environment.NewLine);
fctb2.AppendText(line.line + Environment.NewLine);
break;
case DiffType.Inserted:
fctb1.AppendText(Environment.NewLine);
fctb2.AppendText(line.line + Environment.NewLine, greenStyle);
break;
case DiffType.Deleted:
fctb1.AppendText(line.line + Environment.NewLine, redStyle);
fctb2.AppendText(Environment.NewLine);
break;
}
if (line.subLines != null)
Process(line.subLines);
}
}
}
}
И назовите форму вот так:
var compareForm = new FormCompare();
compareForm.FirstFile = "XmlReplyOld.xml";
compareForm.SecondFile = "XmlReply.xml";
compareForm.ShowDialog();
Если вы не хотите кодировать, то в этом списке вы можете найти полезную утилиту:
https://www.slant.co/topics/3846/~best-folder-file-compare-diff-tools-for-either-osx-linux-or-windows[
^]
Member 14082722
не могли бы вы предоставить код для сравнения двух текстовых файлов и сортировки в C#.я загрузил два текстовых файла(StreamReader r = new StreamReader(FileUpload1.FileContent);
txtp1.Text = r.ReadToEnd();StreamReader r1 = новый StreamReader(FileUpload2.FileContent);
txtp2.Text = r1.ReadToEnd();)теперь я хочу сравнить .пожалуйста, предоставьте свое предложение