如何在 VB.NET 中设置字体类对象的颜色?

发布于 2024-09-25 01:08:01 字数 281 浏览 3 评论 0原文

如何在 VB.NET 中设置字体类对象的颜色? 我的意思是..

   Dim MYfONT As New Font("Microsoft Sans Serif", 16, FontStyle.Bold)
e.Graphics.DrawString(TabMain.TabPages(e.Index).Text, MYfONT, SystemBrushes.HighlightText, paddedBounds)

我怎样才能设置这个字体类对象(MYfONT) - 颜色为黑色。 ?

How to set color for a font class- object in VB.NET..?
i mean..

   Dim MYfONT As New Font("Microsoft Sans Serif", 16, FontStyle.Bold)
e.Graphics.DrawString(TabMain.TabPages(e.Index).Text, MYfONT, SystemBrushes.HighlightText, paddedBounds)

how can i set this font class object(MYfONT) - color to Black. ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶茶白久 2024-10-02 01:08:01

只需将 SystemBrushes.HighlightText 扩展为 New SolidBrush(Color.Black)

Public Sub DrawStringRectangleF(ByVal e As PaintEventArgs)    
    ' Create string to draw.'
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.'
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create rectangle for drawing.'
    Dim x As Single = 150.0F
    Dim y As Single = 150.0F
    Dim width As Single = 200.0F
    Dim height As Single = 50.0F
    Dim drawRect As New RectangleF(x, y, width, height)

    ' Draw rectangle to screen.'
    Dim blackPen As New Pen(Color.Black)
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)

    ' Draw string to screen.'
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect)
End Sub

参考

Just expand your SystemBrushes.HighlightText to a New SolidBrush(Color.Black)

Public Sub DrawStringRectangleF(ByVal e As PaintEventArgs)    
    ' Create string to draw.'
    Dim drawString As [String] = "Sample Text"

    ' Create font and brush.'
    Dim drawFont As New Font("Arial", 16)
    Dim drawBrush As New SolidBrush(Color.Black)

    ' Create rectangle for drawing.'
    Dim x As Single = 150.0F
    Dim y As Single = 150.0F
    Dim width As Single = 200.0F
    Dim height As Single = 50.0F
    Dim drawRect As New RectangleF(x, y, width, height)

    ' Draw rectangle to screen.'
    Dim blackPen As New Pen(Color.Black)
    e.Graphics.DrawRectangle(blackPen, x, y, width, height)

    ' Draw string to screen.'
    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect)
End Sub

Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文