2010-09-25 73 views
2

如何在VB.NET中为字体类对象设置颜色..? 我的意思..如何在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) - 颜色为黑色。 ?

+0

我认为颜色是由支持文本控制对象的前景色属性,即文本框控制。 – asawyer 2010-09-25 04:18:27

+0

这取决于。你如何/在哪里使用这种字体? – 2010-09-25 04:19:21

+0

在tabheader上与矩形一起使用。 – pvaju896 2010-09-25 04:22:21

回答

3

只是扩展SystemBrushes.HighlightTextNew 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

相关问题