TextRenderer.DrawText Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, barvy a písma.
Přetížení
| Name | Description |
|---|---|
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma a barvy. |
| DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování. |
| DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování. |
| DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování. |
| DrawText(IDeviceContext, String, Font, Rectangle, Color, Color) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a barvy pozadí. |
| DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování. |
| DrawText(IDeviceContext, String, Font, Point, Color, Color) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a zadní barvy. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, Color) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a barvy pozadí. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, Color) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a zadní barvy. |
| DrawText(IDeviceContext, String, Font, Rectangle, Color) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma a barvy. |
| DrawText(IDeviceContext, String, Font, Point, Color) |
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma a barvy. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma a barvy. |
| DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, TextFormatFlags) |
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování. |
Poznámky
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma a barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, pt As Point, foreColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
Výjimky
dc je null.
Platí pro
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, backColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText8 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText8(PaintEventArgs e)
{
TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.WordBreak;
TextRenderer.DrawText(e.Graphics, "This is some text that will display on multiple lines.", this.Font,
new Rectangle(10, 10, 100, 50), SystemColors.ControlText, SystemColors.ControlDark, flags);
}
Private Sub RenderText8(ByVal e As PaintEventArgs)
Dim flags As TextFormatFlags = _
TextFormatFlags.Bottom Or TextFormatFlags.WordBreak
TextRenderer.DrawText(e.Graphics, _
"This is some text that will display on multiple lines.", _
Me.Font, New Rectangle(10, 10, 100, 50), _
SystemColors.ControlText, SystemColors.ControlDark, flags)
End Sub
Poznámky
Parametr backcolor se použije v oblasti v parametru bounds. If font, forecolor nebo je backcolor nebo nullEmpty, v uvedeném pořadí; DrawText metoda nakreslí text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen. Výchozí chování TextRenderer je například přidání odsazení do ohraničujícího obdélníku nakresleného textu tak, aby se přizpůsobilo přetečení glyfů. Pokud potřebujete nakreslit řádek textu bez těchto nadbytečných mezer, měli byste použít verze DrawText a MeasureText ty přebírají Size parametr.TextFormatFlags Pro příklad viz MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags).
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Nepodporuje TextRenderer přidávání zarážek tabulátoru k nakreslený text, i když existující zarážky tabulátoru můžete rozbalit pomocí příznaku ExpandTabs .
Platí pro
DrawText(IDeviceContext, String, Font, Point, Color, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, backColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText7 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText7(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "This is some text.", this.Font,
new Point(10, 10), Color.White, Color.SteelBlue, TextFormatFlags.Default);
}
Private Sub RenderText7(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "This is some text.", _
Me.Font, New Point(10, 10), Color.White, Color.SteelBlue, _
TextFormatFlags.Default)
End Sub
Poznámky
Parametr backcolor se použije obdélníkovou oblast obsahující nakreslený text. Pokud font nebo je forecolor nebo nullEmpty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen. Výchozí chování TextRenderer je například přidání odsazení do ohraničujícího obdélníku nakresleného textu tak, aby se přizpůsobilo přetečení glyfů. Pokud potřebujete nakreslit řádek textu bez těchto nadbytečných mezer, měli byste použít verze DrawText a MeasureText ty přebírají Size parametr.TextFormatFlags Pro příklad viz MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags).
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Nepodporuje TextRenderer přidávání zarážek tabulátoru k nakreslený text, i když existující zarážky tabulátoru můžete rozbalit pomocí příznaku ExpandTabs .
Note
Metody DrawText, které určují Point jako levý horní roh nakresleného textu se na Windows 2000 nevykreslují správně. Pokud je vaše aplikace určená pro počítače se systémem Windows 2000, měli byste použít jednu z metod DrawText, které určují Rectangle pro hranice nakresleného textu.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, pt As Point, foreColor As Color, backColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
ModifyString je nastavená.
Platí pro
DrawText(IDeviceContext, String, Font, Rectangle, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText6 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText6(PaintEventArgs e)
{
TextFormatFlags flags = TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis;
TextRenderer.DrawText(e.Graphics, "This is some text that will be clipped at the end.", this.Font,
new Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags);
}
Private Sub RenderText6(ByVal e As PaintEventArgs)
Dim flags As TextFormatFlags = TextFormatFlags.Bottom Or _
TextFormatFlags.EndEllipsis
TextRenderer.DrawText(e.Graphics, _
"This is some text that will be clipped at the end.", _
Me.Font, New Rectangle(10, 10, 100, 50), SystemColors.ControlText, flags)
End Sub
Poznámky
Pokud font nebo je color nebo nullEmpty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen. Výchozí chování TextRenderer je například přidání odsazení do ohraničujícího obdélníku nakresleného textu tak, aby se přizpůsobilo přetečení glyfů. Pokud potřebujete nakreslit řádek textu bez těchto nadbytečných mezer, měli byste použít verze DrawText a MeasureText ty přebírají Size parametr.TextFormatFlags Pro příklad viz MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags).
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Nepodporuje TextRenderer přidávání zarážek tabulátoru k nakreslený text, i když existující zarážky tabulátoru můžete rozbalit pomocí příznaku ExpandTabs .
Platí pro
DrawText(IDeviceContext, String, Font, Rectangle, Color, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a barvy pozadí.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color, backColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText4 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText4(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text.", this.Font,
new Rectangle(10, 10, 70, 70), SystemColors.ControlText,
SystemColors.ControlDark);
}
Private Sub RenderText4(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text.", _
Me.Font, New Rectangle(10, 10, 70, 70), _
SystemColors.ControlText, SystemColors.ControlDark)
End Sub
Poznámky
Parametr backColor se použije v oblasti v parametru bounds . Pokud font, backcolor nebo je forecolor nebo nullEmpty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Výsledkem této metody bude text, který je vodorovně a svisle zarovnaný do středu obdélníku určeného parametrem bounds . Pokud chcete změnit způsob vykreslení textu, použijte verzi DrawText , která přebírá typ parametru TextFormatFlags .
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Platí pro
DrawText(IDeviceContext, String, Font, Point, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText5 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText5(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Some text.",
this.Font, new Point(10, 10), SystemColors.ControlText, TextFormatFlags.Bottom);
}
Private Sub RenderText5(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Some text.", _
Me.Font, New Point(10, 10), SystemColors.ControlText, _
TextFormatFlags.Bottom)
End Sub
Poznámky
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen. Výchozí chování TextRenderer je například přidání odsazení do ohraničujícího obdélníku nakresleného textu tak, aby se přizpůsobilo přetečení glyfů. Pokud potřebujete nakreslit řádek textu bez těchto nadbytečných mezer, měli byste použít verze DrawText a MeasureText ty přebírají Size parametr.TextFormatFlags Pro příklad viz MeasureText(IDeviceContext, String, Font, Size, TextFormatFlags).
Parametr backColor se použije v oblasti v parametru bounds . Pokud font nebo je forecolor nebo nullColor.Empty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Nepodporuje TextRenderer přidávání zarážek tabulátoru k nakreslený text, i když existující zarážky tabulátoru můžete rozbalit pomocí příznaku ExpandTabs .
Note
Metody DrawText, které určují Point jako levý horní roh nakresleného textu se na Windows 2000 nevykreslují správně. Pokud je vaše aplikace určená pro počítače se systémem Windows 2000, měli byste použít jednu z metod DrawText, které určují Rectangle pro hranice nakresleného textu.
Platí pro
DrawText(IDeviceContext, String, Font, Point, Color, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a zadní barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color, backColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText3 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText3(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Point(10, 10), Color.Red, Color.PowderBlue);
}
Private Sub RenderText3(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text", Me.Font, _
New Point(10, 10), Color.Red, Color.PowderBlue)
End Sub
Poznámky
Parametr backColor se použije na obdélníkovou oblast obsahující nakreslený text. Pokud font, backcolor nebo je forecolor nebo nullColor.Empty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen.
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Note
Metody DrawText, které určují Point jako levý horní roh nakresleného textu se na Windows 2000 nevykreslují správně. Pokud je vaše aplikace určená pro počítače se systémem Windows 2000, měli byste použít jednu z metod DrawText, které určují Rectangle pro hranice nakresleného textu.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy, barvy, barvy pozadí a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, bounds As Rectangle, foreColor As Color, backColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
ModifyString je nastavená.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a barvy pozadí.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Drawing::Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Drawing.Color backColor);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, bounds As Rectangle, foreColor As Color, backColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
Výjimky
dc je null.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, pt As Point, foreColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
ModifyString je nastavená.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Point, Color, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma, barvy a zadní barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor, System::Drawing::Color backColor);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor, System.Drawing.Color backColor);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, pt As Point, foreColor As Color, backColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
Výjimky
dc je null.
Platí pro
DrawText(IDeviceContext, String, Font, Rectangle, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma a barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, bounds As Rectangle, foreColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText2 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText2(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Rectangle(10, 10, 100, 100), SystemColors.ControlText);
}
Private Sub RenderText2(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text", _
Me.Font, New Rectangle(10, 10, 100, 100), _
SystemColors.ControlText)
End Sub
Poznámky
Pokud font nebo je forecolor nebo nullColor.Empty , v uvedeném pořadí; DrawText metoda nakreslete text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Výsledkem této metody bude text, který je vodorovně a svisle zarovnaný do středu obdélníku určeného parametrem bounds . Pokud chcete změnit způsob vykreslení textu, použijte verzi DrawText , která přebírá typ parametru TextFormatFlags .
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Viz také
Platí pro
DrawText(IDeviceContext, String, Font, Point, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaném umístění pomocí zadaného kontextu zařízení, písma a barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, System::String ^ text, System::Drawing::Font ^ font, System::Drawing::Point pt, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Point pt, System.Drawing.Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, string? text, System.Drawing.Font? font, System.Drawing.Point pt, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * string * System.Drawing.Font * System.Drawing.Point * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As String, font As Font, pt As Point, foreColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- String
Text, který chcete nakreslit.
Výjimky
dc je null.
Příklady
Následující příklad kódu ukazuje, jak použít metodu DrawText . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows a zavolejte RenderText1 z obslužné rutiny události Paint a předejte e jako PaintEventArgs.
private void RenderText1(PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Regular Text", this.Font,
new Point(10, 10), SystemColors.ControlText);
}
Private Sub RenderText1(ByVal e As PaintEventArgs)
TextRenderer.DrawText(e.Graphics, "Regular Text", _
Me.Font, New Point(10, 10), SystemColors.ControlText)
End Sub
Poznámky
Pomocí jednoho z DrawText přetížení, které přebírá TextFormatFlags parametr, můžete manipulovat s tím, jak je text nakreslen.
Pokud font je null nebo forecolor je Color.Empty, DrawText metoda bude kreslit text v písmu nebo barvě aktuálně vybrané v kontextu zařízení určeném dc. Pokud forecolor ano Transparent, text nebude nakreslen.
Vykreslování textu nabízené TextRenderer třídy je založeno na vykreslování textu GDI a není podporováno pro tisk z model Windows Forms. Místo toho použijte DrawString metody Graphics třídy.
Note
Metody DrawText, které určují Point jako levý horní roh nakresleného textu se na Windows 2000 nevykreslují správně. Pokud je vaše aplikace určená pro počítače se systémem Windows 2000, měli byste použít jednu z metod DrawText, které určují Rectangle pro hranice nakresleného textu.
Viz také
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma a barvy.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, bounds As Rectangle, foreColor As Color)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
Výjimky
dc je null.
Platí pro
DrawText(IDeviceContext, ReadOnlySpan<Char>, Font, Rectangle, Color, TextFormatFlags)
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
- Zdroj:
- TextRenderer.cs
Nakreslí zadaný text v zadaných mezích pomocí zadaného kontextu zařízení, písma, barvy a pokynů k formátování.
public:
static void DrawText(System::Drawing::IDeviceContext ^ dc, ReadOnlySpan<char> text, System::Drawing::Font ^ font, System::Drawing::Rectangle bounds, System::Drawing::Color foreColor, System::Windows::Forms::TextFormatFlags flags);
public static void DrawText(System.Drawing.IDeviceContext dc, ReadOnlySpan<char> text, System.Drawing.Font? font, System.Drawing.Rectangle bounds, System.Drawing.Color foreColor, System.Windows.Forms.TextFormatFlags flags);
static member DrawText : System.Drawing.IDeviceContext * ReadOnlySpan<char> * System.Drawing.Font * System.Drawing.Rectangle * System.Drawing.Color * System.Windows.Forms.TextFormatFlags -> unit
Public Shared Sub DrawText (dc As IDeviceContext, text As ReadOnlySpan(Of Char), font As Font, bounds As Rectangle, foreColor As Color, flags As TextFormatFlags)
Parametry
Kontext zařízení, ve kterém chcete nakreslit text.
- text
- ReadOnlySpan<Char>
Text, který chcete nakreslit.
- flags
- TextFormatFlags
Bitové kombinace TextFormatFlags hodnot.
Výjimky
dc je null.
ModifyString je nastavená.