Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 887
  • Last Modified:

ROTATE TEXT IN VB6 TO PRINTER

This is what I do normal:
 Printer.ScaleMode = 6 'milimeter
 Printer.CurrentX = col
 Printer.CurrentY = row
 Printer.FontName = FontType(fntType)
 Printer.Fontsize = fntSize
 Printer.Print text

But on certain forms I need to rotate part off text either 90 or 180 degrees.
What would be syntax to do so??
0
BIAPRO
Asked:
BIAPRO
  • 4
  • 3
1 Solution
 
lostcarparkCommented:
Unfortunately, the default VB6 printer object has a limited repetoire of functionality, and it doesn't including rotating text on the printer.

Fortunately one of the things it does give you is a "hDC" property, which lets you access the printing "device context", allowing you to roll your own add-on printing routines using the GDI API functions. It's a while since I've done this, and I don't have a copy of VB6 to hand, but I think you need to declare the DrawString function from the GDI library, which lets you specify things like the position, the font, the size, the angle, and of course the text to be drawn.

Good luck!
0
 
BIAPROAuthor Commented:
Will start searching for this kind off syntax, keep u informed
0
 
lostcarparkCommented:
Did a quick test using the GDI, and here's some sample code. To try it out, create a new VB project, and set the AutoRedraw property of Form1 to true, then paste in the following:


Private Const LF_FACESIZE = 32

Private Type LOGFONT
        lfHeight As Long
        lfWidth As Long
        lfEscapement As Long
        lfOrientation As Long
        lfWeight As Long
        lfItalic As Byte
        lfUnderline As Byte
        lfStrikeOut As Byte
        lfCharSet As Byte
        lfOutPrecision As Byte
        lfClipPrecision As Byte
        lfQuality As Byte
        lfPitchAndFamily As Byte
        lfFaceName(1 To LF_FACESIZE) As Byte
End Type

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long


Private Sub Form_Load()

    Dim lf As LOGFONT
    Dim hNewFont As Long
    Dim hOldFont As Long
    Dim sFont As String
    Dim cnt As Integer

    sFont = "Times New Roman"
    For cnt = 1 To Len(sFont)
        lf.lfFaceName(cnt) = Asc(Mid$(sFont, cnt, 1))
    Next cnt
    lf.lfHeight = 48
    lf.lfEscapement = 3600
    hNewFont = CreateFontIndirect(lf)
    hOldFont = SelectObject(Me.hdc, hNewFont)

    sFont = "Times New Roman"
    For cnt = 1 To Len(sFont)
        lf.lfFaceName(cnt) = Asc(Mid$(sFont, cnt, 1))
    Next cnt
    lf.lfHeight = 48

    For cnt = 0 To 3600 Step 200
        lf.lfEscapement = cnt
        hNewFont = CreateFontIndirect(lf)
        hOldFont = SelectObject(Me.hdc, hNewFont)
       
        Me.CurrentX = 2000
        Me.CurrentY = 2000
        Me.Print "Text at an angle"
       
        SelectObject Me.hdc, hOldFont
        DeleteObject hNewFont
    Next cnt

End Sub


This creates a font and makes it default for the device context. Once that's done, you can use the normal drawing functions to output text at the specidied angle. When you're done, set the device context back to the original font and destroy the one you created so you don't waste resources.

This example draws a circle of text on the screen. To switch output to the printer, all you have to do is change every "Me" to "Printer".

Hope this helps!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BIAPROAuthor Commented:
Ok, did made the changes from me.   to printer.   wil print plain horizontal line on printer with text, on screen it will create angles, what do I wrong?
Regards Jack
0
 
lostcarparkCommented:
Did you change every instance of me to printer?


    sFont = "Times New Roman"
    For cnt = 1 To Len(sFont)
        lf.lfFaceName(cnt) = Asc(Mid$(sFont, cnt, 1))
    Next cnt
    lf.lfHeight = 48

    For cnt = 0 To 3600 Step 200
        lf.lfEscapement = cnt
        hNewFont = CreateFontIndirect(lf)
        hOldFont = SelectObject(Printer.hdc, hNewFont)
       
        Printer.CurrentX = 2000
        Printer.CurrentY = 2000
        Printer.Print "Text at an angle"
       
        SelectObject Printer.hdc, hOldFont
        DeleteObject hNewFont
    Next cnt

By the way, I seem to have left some redundant code in my original post.
0
 
BIAPROAuthor Commented:
Ok, got it working now,  problem was printerdriver
0
 
lostcarparkCommented:
Glad to hear it's working.

Best of luck,

James
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now