![](/img/trans.png)
[英]How to Create a dynamic pages in Active reports 6 using C# winforms?
[英]How to create a label with multiple styles in it using C# winforms?
在WinForms中創建Label
時, ForeColor
是ControlText
, BackColor
是Control
,它們會產生這種Label
:
我希望能夠為標簽內的某些單詞設置不同的ForeColor
,不同的BackColor
和不同的Font
(粗體)。 像這樣:
我用谷歌搜索,但是我發現的只是改變整個標簽樣式的答案。 那么我該如何完成我所描述的?
如果沒有使用內置C#素材的簡單方法,該如何處理?
我同意ChrisF的觀點,只讀RichTextBox最適合此目的。
這是我過去使用過的只讀RichTextBox控件的示例。
public class DisabledRichTextBox : RichTextBox
{
private const int WmSetfocus = 0x07;
private const int WmEnable = 0x0A;
private const int WmSetcursor = 0x20;
protected override void WndProc(ref Message m)
{
if (!(m.Msg == WmSetfocus || m.Msg == WmEnable || m.Msg == WmSetcursor))
{
base.WndProc(ref m);
}
}
}
使用代碼:
將新類添加到您的項目。 個人而言,我想補充一個新.cs
稱為類似文件DisabledRichTextBox.cs
。 將此代碼粘貼在namespace
標簽之間:
using whatever; namespace YourNamespace { // Code here }
正常構建項目。
DisabledRichTextBox
的新控件,或者您所稱的名稱。 .Rtf
(richtext)屬性設置為一些適當的RichText。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.