我在我加入一個RichTextBox設計師創造了一個新的UserControl
。然後,我的確在UserControl
構造:我如何在richTextBox1上繪圖?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScrollLabelTest
{
public partial class ScrollText : UserControl
{
Font drawFonts1 = new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel);
Point pt = new Point(50, 50);
public ScrollText()
{
InitializeComponent();
System.Drawing.Font f = new System.Drawing.Font("hi",5);
Graphics e = richTextBox1.CreateGraphics();
e.DrawString("hello",drawFonts1,new SolidBrush(Color.Red),pt);
this.Invalidate();
}
}
}
於是我拖着新UserControl
到form1
設計師,但它是空的。我沒看到「你好」這個詞。
你已經安裝的字體被稱爲 「喜」?哦,等等,你沒有使用'f'。 – gunr2171
只要你'Invalidate',你的'Form'重新繪製本身,包括你的'RickTextBox'控制(我猜),反過來'RickTextBox'控制重繪自己和除去繪製了它額外的東西的東西。 – sallushan
刪除Invalidate沒有幫助。試圖使richTextBox1.Invalidate在所有情況下它沒有繪製文本。有或沒有無效。 – user3756594