注册 登录
编程论坛 VB.NET论坛

有关字体

mthupc 发布于 2008-07-25 22:40, 1154 次点击
朋友们,通过下面两段代码,希望能指点兄弟一下:6.0的textheight、textwidth与2005的MeasureString(,)区别在哪儿,为什么二者输出结果值差别这么大?或者各自到底指的是什么?好郁闷!
谢谢了!

vb6.0

Private Sub Command1_Click()
Me.Font.Name = "Arial"
Me.Font.Size = 24
          Me.Font.Bold = True
          Me.ForeColor = vbRed
          Print "Hello   World!"
          Line (0, 0)-(TextWidth("Hello   World!"), TextHeight("Hello   World!")), vbBlack, B
          MsgBox Str(TextHeight("Hello   World!"))
End Sub




vb2005

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim g As System.Drawing.Graphics
        g = Me.CreateGraphics

        Dim TextFont As New System.Drawing.Font("Arial", 24, FontStyle.Bold)
        MsgBox(TextFont.Height.ToString)

        Dim TextBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
        g.DrawString("Hello   World!", TextFont, TextBrush, 10, 10)
        Dim TextSize As New System.Drawing.SizeF
        TextSize = g.MeasureString("Hello   World!", TextFont)
        g.DrawRectangle(Pens.Black, 10, 10, TextSize.Width, TextSize.Height)
        MsgBox(Str(TextSize.Height))
        TextFont.Dispose()
        TextBrush.Dispose()
    End Sub
0 回复
1