CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Center Print

  1. #1
    Join Date
    Apr 2001
    Posts
    4

    Center Print

    Hi Everyone,

    I have a couple of text boxes and labels that I would like to have printed down the center of a standard piece of paper, but have no idea how to accomplish this. I would appreciate any help. Thank you.


  2. #2
    Join Date
    Mar 2001
    Location
    Alberta, Canada
    Posts
    7

    Re: Center Print

    I believe it would go something like this...

    label.top=(screen.height-label.height)/2
    label.left=(screen.width-label.width)/2

    I think that if you set the form this way as well you should get the desired effect.
    If I've misinterpreted your question, send me a message.

    Chris

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Center Print

    Private Sub Command1_Click()
    '==========================
    Dim sStr As String
    Dim iPageWidth As Integer

    sStr = "aaa"
    iPageWidth = 80 'if font <>12 then pagewidth is different from 80
    Printer.Font = "Courier"
    Printer.FontSize = 12
    Printer.Print CenterString(iPageWidth, sStr)
    Printer.NewPage
    Printer.EndDoc
    End Sub

    Private Function CenterString(ByVal iCharOnPage As Integer, ByVal sString As String) As String
    '=============================================================================
    CenterString = Left(Space(iCharOnPage / 2), Len(Space(iCharOnPage / 2)) - Len(sString) / 2) & sString
    End Function


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jun 2000
    Location
    Jhb, Gauteng RSA
    Posts
    21

    Re: Center Print

    You can also center each item:


    ' to Center the contents of myStr
    myStr = "Center This"
    'get the width of the string in twips
    txtW = Printer.TextWidth(myStr)
    'Divide this answer by 2
    MyMid = txtW/2
    'Calculate the middle of the Printed page
    paperMid = Printer.Scalewidth/2
    'Subtract the middle of the text (MyMid) from PaperMid
    txtStart = paperMid - MyMid
    'set the print Co-Ords
    Printer.CurrentX = txtStart
    'The .CurrentY will be set From Previous print Commands or 0
    'The next Command will print the string exactly in the middle of the page
    Printer.print
    ' If you want middle from top to bottom, Replace Printer.TextWidth with
    ' Printer.TextHeight and .ScaleWidth with .ScaleHeight




    Hope this helps
    RobZ

    Printer.Print myStr




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured