现在有一个字符串,要求打印它。用户可以设置字体、
怎么得到打印字体的高度和宽度呢?

解决方案 »

  1.   

    Debug.Print Printer.Font.Size
    Debug.Print Printer.Font.Weight
      

  2.   

    怎么设置全局变量?
    Global count As Integer
    这样在一个模块中声明了,在其它地方怎么不能用啊?
    用的时候说:编译错误,函数或接口标记为限制的,或函数中使用了VB不支持的自动类型
      

  3.   

    public count As Integer
      

  4.   

    用public count As Integer
    打印的东西CSDN上很多,自己搜艘吧Private Sub Command1_Click()
    Dim Answer As String, HorizontalMargin, VerticalMargin As Single
    Dim MyCenteredText As String, MyCenteredTextWidth As Single
    Dim MyLeftText As String, MyLeftTextWidth As Single
    Dim MyRightText As String, MyRightTextWidth As Single
    Dim txtGrid11, txtGrid12, txtGrid13, txtGrid14, txtGrid21, txtGrid22 As String
    Dim txtGrid23, txtGrid24, txtGrid31, txtGrid32, txtGrid33, txtGrid34 As String
    Dim MyGridTitle As String, MyGridTitleWidth As Single
    Dim Row1Col1Left, Row1Col2Left, Row1Col3Left, Row1Col4Left As Single
    Dim Row2Col1Left, Row2Col2Left, Row2Col3Left, Row2Col4Left As Single
    Dim Row3Col1Left, Row3Col2Left, Row3Col3Left, Row3Col4Left As Single
    Dim Row1Top, Row2Top, Row3Top, ImageLeft, ImageTop As Single
    Answer = MsgBox("confirm printing on " & Printer.DeviceName, vbYesNo)
    If Answer = vbNo Then Exit Sub
    Printer.ScaleMode = vbCentimeters
    HorizontalMargin = (21 - Printer.ScaleWidth) / 2
    VerticalMargin = (29.7 - Printer.ScaleHeight) / 2
    HorizontalMargin = 1 + HorizontalMargin
    VerticalMargin = 1.5 + VerticalMargin
    Printer.Print "";
    Printer.Line (HorizontalMargin, VerticalMargin)-(21 - HorizontalMargin, 29.7 - VerticalMargin), RGB(255, 0, 0), B
    Printer.FontName = "Arial"
    Printer.FontSize = 12
    Printer.FontBold = True          'we want bold
    Printer.FontItalic = False       'no italic
    Printer.FontUnderline = False    'no underline
    Printer.FontStrikethru = False   'no strike
    Printer.ForeColor = RGB(0, 0, 0) 'color black
    MyCenteredText = "This is centered text in Arial 12 Bold"
    MyCenteredTextWidth = Printer.TextWidth(MyCenteredText)
    Printer.CurrentX = (21 - MyCenteredTextWidth) / 2
    Printer.CurrentY = VerticalMargin + 0.5
    Printer.Print MyCenteredText
    Printer.FontName = "Courier New"
    Printer.FontSize = 10
    Printer.FontBold = False         'no bold
    Printer.FontItalic = True        'we use italic
    Printer.FontUnderline = False    'no underline
    Printer.FontStrikethru = False   'no strike
    Printer.ForeColor = RGB(0, 0, 0) 'color blackMyLeftText = "Courier New on the Left"
    MyLeftTextWidth = Printer.TextWidth(MyLeftText)
    If MyLeftTextWidth > 21 - (HorizontalMargin * 2) Then Exit SubPrinter.CurrentX = HorizontalMargin
    Printer.CurrentY = VerticalMargin + 2
    Printer.Print MyLeftText;MyRightText = "Courier New on the Right"
    MyRightTextWidth = Printer.TextWidth(MyRightText)
    If MyRightTextWidth > 21 - (HorizontalMargin) Then Exit Sub
    Printer.CurrentX = 21 - (HorizontalMargin) - MyRightTextWidth
    Printer.Print MyRightTexttxtGrid11 = "row1 & col1"
    txtGrid12 = "row1 & col2"
    txtGrid13 = "row1 & col3"
    txtGrid14 = "row1 & col4"
    txtGrid21 = "row2 & col1"
    txtGrid22 = "row2 & col2"
    txtGrid23 = "row2 & col3"
    txtGrid24 = "row2 & col4"
    txtGrid31 = "row3 & col1"
    txtGrid32 = "row3 & col2"
    txtGrid33 = "row3 & col3"
    txtGrid34 = "row3 & col4"
    Printer.ForeColor = RGB(0, 255, 0)Printer.Line (1 + HorizontalMargin, 4 + VerticalMargin)-(16 + HorizontalMargin, 4 + VerticalMargin)
    Printer.Line (1 + HorizontalMargin, 7 + VerticalMargin)-(16 + HorizontalMargin, 7 + VerticalMargin)
    Printer.Line (1 + HorizontalMargin, 4 + VerticalMargin)-(1 + HorizontalMargin, 7 + VerticalMargin)
    Printer.Line (16 + HorizontalMargin, 4 + VerticalMargin)-(16 + HorizontalMargin, 7 + VerticalMargin)
    Printer.Line (1 + HorizontalMargin, 5 + VerticalMargin)-(16 + HorizontalMargin, 5 + VerticalMargin)
    Printer.Line (1 + HorizontalMargin, 6 + VerticalMargin)-(16 + HorizontalMargin, 6 + VerticalMargin)
    Printer.Line (3 + HorizontalMargin, 4 + VerticalMargin)-(3 + HorizontalMargin, 7 + VerticalMargin)
    Printer.Line (9 + HorizontalMargin, 4 + VerticalMargin)-(9 + HorizontalMargin, 7 + VerticalMargin)
    Printer.Line (14 + HorizontalMargin, 4 + VerticalMargin)-(14 + HorizontalMargin, 7 + VerticalMargin)Printer.ForeColor = RGB(0, 0, 0)Printer.FontName = "Arial"
    Printer.FontSize = 10
    Printer.FontBold = False         'no bold
    Printer.FontItalic = False       'no italic
    Printer.FontUnderline = False    'no underline
    Printer.FontStrikethru = False   'no strike
    MyGridTitle = "And this is a little table"
    MyGridTitleWidth = Printer.TextWidth(MyGridTitle)
    Printer.CurrentX = HorizontalMargin + 1 + ((15 - MyGridTitleWidth) / 2)
    Printer.CurrentY = 4 + VerticalMargin - (Printer.TextHeight(MyGridTitle) + 0.1)
    Printer.Print MyGridTitle
    Row1Col1Left = 1 + HorizontalMargin + 0.1
    Row1Col2Left = 3 + HorizontalMargin + 0.1
    Row1Col3Left = 9 + HorizontalMargin + 0.1
    Row1Col4Left = 14 + HorizontalMargin + 0.1Row1Top = 4 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
    '
    Row2Top = 5 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
    Row3Top = 6 + VerticalMargin + ((1 - Printer.TextHeight(txtGrid11)) / 2)
    '
    Row2Col1Left = 1 + HorizontalMargin + 0.1 '(column 1)
    Row2Col2Left = 3 + HorizontalMargin + 0.1 '(column 2)
    Row2Col3Left = 9 + HorizontalMargin + 0.1 '(column 3)
    Row2Col4Left = 14 + HorizontalMargin + 0.1 '(column 4)
    '
    Row3Col1Left = 1 + HorizontalMargin + 0.1 '(column 1)
    Row3Col2Left = 3 + HorizontalMargin + 0.1 '(column 2)
    Row3Col3Left = 9 + HorizontalMargin + 0.1 '(column 3)
    Row3Col4Left = 14 + HorizontalMargin + 0.1 '(column 4)
    '
    Printer.CurrentY = Row1Top
    Printer.CurrentX = Row1Col1Left
    Printer.Print txtGrid11;
    Printer.CurrentX = Row1Col2Left
    Printer.Print txtGrid12;
    Printer.CurrentX = Row1Col3Left
    Printer.Print txtGrid13;
    Printer.CurrentX = Row1Col4Left
    Printer.Print txtGrid14
    '
    Printer.CurrentY = Row2Top
    Printer.CurrentX = Row2Col1Left
    Printer.Print txtGrid21;
    Printer.CurrentX = Row2Col2Left
    Printer.Print txtGrid22;
    Printer.CurrentX = Row2Col3Left
    Printer.Print txtGrid23;
    Printer.CurrentX = Row2Col4Left
    Printer.Print txtGrid24
    '
    Printer.CurrentY = Row3Top
    Printer.CurrentX = Row3Col1Left
    Printer.Print txtGrid31;
    Printer.CurrentX = Row3Col2Left
    Printer.Print txtGrid32;
    Printer.CurrentX = Row3Col3Left
    Printer.Print txtGrid33;
    Printer.CurrentX = Row3Col4Left
    Printer.Print txtGrid34Picture2.ScaleMode = vbCentimeters
    Picture2.Picture = LoadPicture(App.Path & "\dark_shadow.jpg")
    Picture2.AutoSize = True
    Picture2.Refresh
    Picture2.AutoSize = FalseImageLeft = (21 - Picture2.ScaleWidth) / 2ImageTop = 12Printer.ScaleMode = vbCentimeters
    Printer.PaintPicture Picture2.Picture, ImageLeft, ImageTopPrinter.EndDoc
    End SubPrivate Sub Command2_Click()
    End
    End Sub
      

  5.   

    Global count As Integer
    public count As Integer两个都可以
      

  6.   

    Global count As Integer
    确实会出现上面讲的错误,但该为count1之类的就不会了,难到count也是VB中的关键字,不会吧。我不知道。
      

  7.   

    count是保留字,不能用的,换一个变量名就行了。
      

  8.   

    Debug.Print Printer.Font.height
    Debug.Print Printer.Font.width
      

  9.   

    printer对象好象没上面两中属性
      

  10.   

    printer没有啊,那怎么得到字体的长度呢?
      

  11.   

    设置字号:          printer.font.size=24  '此处数字为你想要的字号,但实际的字号和你设置的字号可能有点差别,这是因为windows没有那种大小的字号。
    设置字体的粗细:    printer.font.weight=400 '可设置为0~900,但目前windows只支持两种粗细    400:正常字体   900:粗体字
    设置字体的字符集:  printer.Font.Charset =""  '此处写上你想要的字体