zoukankan      html  css  js  c++  java
  • C# WinForm 中Console 重定向输出到ListBox控件中显示

     1 public class TextBoxWriter : System.IO.TextWriter
     2     {
     3         ListBox lstBox;
     4         delegate void VoidAction();
     5 
     6         public TextBoxWriter(ListBox box)
     7         {
     8             lstBox = box;
     9         }
    10 
    11         public override void Write(string value)
    12         {
    13             VoidAction action = delegate
    14             {
    15                 lstBox.Items.Insert(0string.Format("[{0:HH:mm:ss}]{1}", DateTime.Now, value));
    16             };
    17             lstBox.BeginInvoke(action);
    18         }
    19 
    20         public override void WriteLine(string value)
    21         {
    22             VoidAction action = delegate
    23             {
    24                 lstBox.Items.Insert(0string.Format("[{0:HH:mm:ss}]{1}", DateTime.Now, value));
    25             };
    26             lstBox.BeginInvoke(action);
    27         }
    28 
    29         public override System.Text.Encoding Encoding
    30         {
    31             get { return System.Text.Encoding.UTF8; }
    32         }
    33     }    
      void frmMain_Load(object sender, EventArgs e)
            {
                Console.SetOut(new TextBoxWriter(Instances.ucLog.LogBox));
            }
  • 相关阅读:
    Windows远程桌面连接CentOS 7
    CentOS7 系统菜单中添加快捷方式
    CentOS 7 创建桌面快捷方式
    Centos7 可执行程序自定义为系统服务
    CentOS 7 中 Docker 的安装
    CentOS 7 需要安装的常用工具,及centos安装fcitx 搜狗输入法的坑旅
    C++中结构体与类的区别 2
    C++中结构体与类的区别 1
    C++ 11 自旋锁
    Imply.io单机安装
  • 原文地址:https://www.cnblogs.com/94cool/p/4409122.html
Copyright © 2011-2022 走看看