如何:在指定的位置繪製文字
當您執行自訂繪圖時,可以在從指定點開始的單一水平線中繪製文字。 您可以使用採用 Point 或 PointF 參數之 類別的多 Graphics 載方法,以這種方式 DrawString 繪製文字。 方法 DrawString 也需要 Brush 和 Font
您也可以使用 DrawText 採用 的多載方法 TextRendererPoint 。 DrawTextColor也需要 和 Font 。
下圖顯示當您使用多載方法時,于指定點繪製的 DrawString 文字輸出。
使用 GDI+ 繪製文字行
DrawString使用 方法,傳遞您想要的文字,或 PointF 、 PointFont 和 Brush 。
using (Font font1 = new Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)){ PointF pointF1 = new PointF(30, 10); e.Graphics.DrawString("Hello", font1, Brushes.Blue, pointF1); }
Dim font1 As New Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel) Try Dim pointF1 As New PointF(30, 10) e.Graphics.DrawString("Hello", font1, Brushes.Blue, pointF1) Finally font1.Dispose() End Try
使用 GDI 繪製文字行
DrawText使用 方法,傳遞您想要的文字 、 Point 、 Font 和 Color 。
using (Font font = new Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel)) { Point point1 = new Point(30, 10); TextRenderer.DrawText(e.Graphics, "Hello", font, point1, Color.Blue); }
Dim font As New Font("Times New Roman", 24, FontStyle.Bold, GraphicsUnit.Pixel) Try Dim point1 As New Point(30, 10) TextRenderer.DrawText(e.Graphics, "Hello", font, point1, Color.Blue) Finally font.Dispose() End Try
編譯程式碼
上述範例需要:
- PaintEventArgs
e
,這是 的參數 PaintEventHandler 。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應