У меня есть программа, которая контролирует отладочные сообщения, и я попытался использовать TextBox и приложил к ней сообщения, но он не масштабируется очень хорошо и замедляется, когда число сообщений становится большим. Затем я попробовал ListBox, но прокрутка была привязана к вершине при добавлении новых сообщений. Он также не позволяет вырезать и вставлять, как это делает текстовое поле.
Что такое лучший способ реализовать консольный элемент, встроенный в окно winforms.
Изменить: Я все равно хотел бы добавить окно вывода, такое как визуальная студия, но поскольку я не могу найти простой способ, вот два решения, которые я использую. В дополнение к использованию RichTextBox, который работает, но вы должны его очищать время от времени. Я использую консоль, которую я вызываю. Вот небольшой класс оболочки, который я написал, чтобы справиться с этим.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Con
{
class Ext_Console
{
static bool console_on = false;
public static void Show(bool on,string title)
{
console_on = on;
if (console_on)
{
AllocConsole();
Console.Title = title;
// use to change color
Console.BackgroundColor = System.ConsoleColor.White;
Console.ForegroundColor = System.ConsoleColor.Black;
}
else
{
FreeConsole();
}
}
public static void Write(string output)
{
if (console_on)
{
Console.Write(output);
}
}
public static void WriteLine(string output)
{
if (console_on)
{
Console.WriteLine(output);
}
}
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();
[DllImport("kernel32.dll")]
public static extern Boolean FreeConsole();
}
}
// example calls
Ext_Console.Write("console output ");
Ext_Console.WriteLine("console output");
Ext_Console.Show(true,"Title of console");