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

标签 .net vb.net fonts

如何在 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) - 颜色为黑色。 ?

最佳答案

只需将 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

Reference

关于.net - 如何在 VB.NET 中设置字体类对象的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3792469/

相关文章:

c# - 我需要在 C# 中的 EWS 的帮助下接收电子邮件

.net - web.config 和 connectionStrings 中的引号

vb.net - vb.net计时器和异常(尝试…捕获)和内存泄漏

svg - 是否可以从命令行从 SVG 创建字体 (TTF)?

java - 确保嵌入的字体资源已加载到 Android 上

css - @font-face 质量问题

C#:是否与 C# 的 php ctype_digit 函数类似?

c# - 查询数据库中的每条记录比使用 LINQ 更快

regex - 如何删除 vb.net 中方括号之间的空格?

vb.net - 怎么解决这个问题。该进程无法访问该文件