1. 程式人生 > >C# RichTextBox顯示不同顏色文字

C# RichTextBox顯示不同顏色文字

#region 日誌記錄、支援其他執行緒訪問 
public delegate void LogAppendDelegate(Color color, string text); 
/// <summary> 
/// 追加顯示文字 
/// </summary> 
/// <param name="color">文字顏色</param> 
/// <param name="text">顯示文字</param> 
public void LogAppend(Color color, string text) 

    richTextBoxRemote.AppendText("\n"); 
    richTextBoxRemote.SelectionColor = color; 
    richTextBoxRemote.AppendText(text); 

/// <summary> 
/// 顯示錯誤日誌 
/// </summary> 
/// <param name="text"></param> 
public void LogError(string text) 

    LogAppendDelegate la = new LogAppendDelegate(LogAppend); 
    richTextBoxRemote.Invoke(la, Color.Red, DateTime.Now.ToString("HH:mm:ss ") + text); 

/// <summary> 
/// 顯示警告資訊 
/// </summary> 
/// <param name="text"></param> 
public void LogWarning(string text) 

    LogAppendDelegate la = new LogAppendDelegate(LogAppend); 
    richTextBoxRemote.Invoke(la, Color.Violet, DateTime.Now.ToString("HH:mm:ss ") + text); 

/// <summary> 
/// 顯示資訊 
/// </summary> 
/// <param name="text"></param> 
public void LogMessage(string text) 

    LogAppendDelegate la = new LogAppendDelegate(LogAppend); 
    richTextBoxRemote.Invoke(la, Color.Black, DateTime.Now.ToString("HH:mm:ss ") + text); 

#endregion

from:

相關推薦

C# RichTextBox顯示不同顏色文字

#region 日誌記錄、支援其他執行緒訪問  public delegate void LogAppendDelegate(Color color, string text);  /// <summary>  /// 追加顯示文字  /// </summa

c#中richtextbox顯示不同顏色

List strWarn=new List();//定義一個泛型,可以自由的新增欄位 private void WarnInfo(string str) { strWarn.Add(str); for (in

swift label文字顯示不同顏色(字型)

 根據 Stack Overflow 上的這篇文章 大概有三種方法: 1. 先設定整個 text 為 NSMutableAttributedString, 再使用 Range 設定要改變顏色(字型)的文字 var myString:NSString = "I AM KIR

EasyUI-DataGrid下資料庫數字替換成文字資訊顯示以及不同狀態顯示不同顏色

EasyUI-DataGrid下資料庫數字替換成文字資訊顯示 在使用easyui作為開發框架的時候,經常遇到一些常見的問題,比如某項資料名,在資料庫裡存的是0和1等,然後顯示在頁面上的時候,需要顯示成“

textView 文字顯示不同顏色

一下是具體用到的程式碼: SpannableStringBuilder builder = new SpannableStringBuilder(message+message2); ForegroundColorSpan redSpan = new ForegroundC

Android同一個TevtView顯示不同顏色文字,新增不同的點選事件。

一下程式碼在同一個Textview裡面設定了2段不同的文字和點選事件。 TextView protocalTv=(TextView)findViewById(R.id.protocal); String str=protocalTv.getText().toString(

如何在一個TextView中顯示不同顏色文字

在唯品會app中,我們可以看到它裡面有些文字控制元件能夠顯示不同顏色的文字,這種效果看起來蠻不錯的。先上個效果圖: 其實,在這上面使用的是一個TextView控制元件來顯示這段文字的。而文字內容是使用html的格式實現的,程式碼如下: text.setText(Html.

c windows控制檯輸出顏色文字

#include <windows.h> //設定文字顏色void SetColor(int ForgC){ WORD wColor; //We will need this handle to get the current background attribute HANDLE hStdOu

彙編——在螢幕中間顯示不同顏色的字串

程式設計:參考教材實驗9,在螢幕中間分別顯示綠色、綠底紅色、白底藍色的字串’welcome to masm’。 一、分析 8086CPU中,80x25彩色字元模式顯示緩衝區的結構:記憶體地址空間中,B8000H~BFFFFH共32kb的空間,為80x25彩色字元模式的顯示緩衝區。向這

android 中使用TextView實現分段顯示不同顏色的字串

一、最容易想到的是使用多個TextView,設定其android:textColor="#000000" 二、使用HTML標籤 String content="我要顯示<font color='#FF0000'>紅色</font>"; TextVi

Echarts柱狀圖的每個柱子顯示不同顏色問題

在使用Echarts製作柱狀圖的時候,通常在橫軸每個標籤只有一個柱子的時候,每個柱子的顏色都是一樣的,如下圖所示: 然而,很多時候我們為了使介面更加美觀,通常會有使每個柱子顏色都不相同的需求。那麼這時候,我們需要在itemStyle的normal狀態下,首

【Android】一個TextView顯示不同顏色字型

tv.setText(Html.fromHtml( "<font color=#FF504B>"+Str1+"</font> "+ "<font color=#696969>"+Str2+"</font>")); 利用ht

#Qt入門#---------label中顯示不同顏色的字元

因為除錯需要,現在要用不同顏色高亮,方便觀察資料。 具體方法是這樣的: label->setText(                                QObject::tr

PyCharm外掛之Ideolog,更加直觀的檢視log日誌,根據等級顯示不同顏色

1.首先你的pycharm版本要在2017以上 2.其次安裝JetBrains官方提供的外掛 File | Settings | Plugins 3.搜尋 Ideolog這個外掛,安裝以後,重啟pyc

C# TreeView顯示圖片和文字對應

首先在工具欄中拖出TreeView和ImageList並在ImageList中新增圖片 this.treeView1.ShowLines = false; this.treeView1.ShowPlusMinus = false; this.treeVie

Ubuntu配置vim及不同語法顯示不同顏色

第一步、安裝vim 命令為:sudo apt-get install vim 第二步、更改vim的配置檔案etc/vim命令為:(1)cd/etc/vim   (2)sudo gedit vimrc                  (1) 進入/etc/vim目錄.(2)

Android問題集(二)——TextView在點選時顯示不同顏色,Button點選效果

1、在res目錄下新建名為color資料夾; 2、在color中新建text_color.xml檔案,並選擇selector選項(如下圖): 3、在text_color.xml中填寫如下程式碼: <?xml version="1.0"

QT進度條根據百分比顯示不同顏色

引用 4 樓 ak47zhangzhiwei 的回覆:使用Qt 的styleSheet 可以實現:用於計算比例:C/C++ codeQString CMainWidget::calcValue(int nValue,int nTotal){    QString strStyle = "";    int v

iOS 在一個UILabel上顯示不同顏色

self.addressLabel = [[UILabelalloc]initWithFrame:CGRectZero]; self.addressLabel.textColor = [UICol

textview 設定text 一行顯示不同顏色引入 Html

holder.Page_index.setText(Html.fromHtml("第" + "<font color=#EC7F35>" + (position + 1)