How to Print Text Sideways in Picture Control with Windows API

ID: Q99874


The information in this article applies to:


SUMMARY

The example below shows how to print text sideways in a picture control using Windows API function calls. The text prints vertically in the picture control, rotated by 90 degrees.


MORE INFORMATION

Step-by-Step Example

  1. Start Visual Basic. Form1 is created by default.


  2. Draw a large picture box (Picture1) on the form.


  3. From the File menu, choose New Module to create a new module. Put the following code in the module:
    
       DefInt A-Z
       global Const LF_FACESIZE = 32
       Type LOGFONT
          lfheight As Integer
          lfwidth As Integer
          lfescapement As Integer
          lforientation As Integer
          lfweight As Integer
          lfitalic As String * 1
          lfunderline As String * 1
          lfstrikeout As String * 1
          lfcharset As String * 1
          lfoutprecision As String * 1
          lfclipprecision As String * 1
          lfquality As String * 1
          lfpitchandfamily As String * 1
          lffacename As String * LF_FACESIZE
       End Type
    
       ' Enter each of the following 7 Declare statement on one, single line:
    
       Declare Function CreateFont% Lib "GDI" (ByVal h%, ByVal w%, ByVal e%,
          ByVal o%, ByVal n%, ByVal i%, ByVal u%, ByVal s%, ByVal c%,
          ByVal op%, ByVal cp%, ByVal q%, ByVal j%, ByVal f$)
       Declare Function createfontindirect Lib "GDI" (lplogfont As LOGFONT)
          As Integer
       Declare Function selectobject Lib "GDI" (ByVal hdc%, ByVal object%)
          As Integer
       Declare Function textout Lib "GDI" (ByVal hdc%, ByVal x%, ByVal y%,
          ByVal text$, ByVal ncount%) As Integer
       Declare Sub deleteobject Lib "GDI" (ByVal object%)
       Declare Function getdevicecaps Lib "GDI" (ByVal hdc%, ByVal nindex%)
          As Integer
       Declare Function gettextface Lib "GDI" (ByVal hdc As Integer,
          ByVal ncount As Integer, ByVal lpname As String) As Integer
    
       Global Const PROOF_QUALITY = 2
       Global Const FW_NORMAL = 400
     


  4. Add the following code to the Form_Click event:
    
       picture1.Cls
       Dim hfont As Integer, holdfont As Integer
       Dim font As LOGFONT
       nvalue = getdevicecaps(picture1.hDC, 34)
       font.lfheight = 12
       font.lfwidth = 0
       font.lfescapement = 900
       font.lforientation = 900
       font.lfweight = 400    'This is normal
       font.lfitalic = Chr$(0)
       font.lfunderline = Chr$(0)
       font.lfstrikeout = Chr$(0)
       font.lfcharset = Chr$(0)
       font.lfoutprecision = Chr$(0)
       font.lfclipprecision = Chr$(0)
       font.lfquality = Chr$(2)
       font.lfpitchandfamily = Chr$(33)
       font.lffacename = "Courier New" + Chr$(0)
    
       hfont = createfontindirect(font)
       holdfont = selectobject(picture1.hDC, hfont)
       szfacename$ = Space$(80)
       retval% = gettextface(picture1.hDC, 79, szfacename$)
    
       nchars = Len(sometext$)
       picture1.CurrentX = 200
       picture1.CurrentY = 2000
       picture1.Print Left$(RTrim$(szfacename$), Len(RTrim$(szfacename$)) - 1)
       deleteobject hfont
     


  5. Run the program. Click the form, not the picture. You'll see the phrase "Courier New" print sideways in the picture control, from the lower left to the upper left.


Additional query words: 1.00 2.00 3.00


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: June 7, 1999