Results 1 to 6 of 6

Thread: Print a form in centre alignment

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Print a form in centre alignment

    Hi All,

    I am developing a new project to print details on a cheque leaf. I have a form noramally with the size of a normal cheque leaf.
    The form is inclueded some text boxes to put date, name of the beneficiary, amount and amount in words.

    Now I want to print this form on a cheque leaft. I have the idea to print the form that I get from : http://www.vb-helper.com/howto_print...textboxes.html

    But the problem, this print is left aligned. I want to print the data on a cheque leaf which is placed on the center of the tray of a Laser printer.

    So any body has idea to align center to printer form.

    With regards,

    Nasreen

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Print a form in centre alignment

    Code:
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Const VK_MENU As Byte = &H12
    Private Const VK_SNAPSHOT As Byte = &H2C
    Private Const KEYEVENTF_KEYUP = &H2
    Private Sub Command1_Click()
    
        Dim lWidth As Long
        Dim lHeight As Long
        
        Clipboard.Clear
        Call keybd_event(VK_MENU, 0, 0, 0)
        Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
        DoEvents
        Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
        Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
        
        Printer.Print
        
        If Width > Printer.ScaleWidth Then
            lWidth = Printer.ScaleWidth
            lHeight = (Printer.ScaleWidth / Width) * Height
        Else
            lWidth = Width
            lHeight = Height
        End If
        
        Printer.PaintPicture Clipboard.GetData, (Printer.ScaleWidth - Width) / 2, 0, lWidth, lHeight
        Printer.EndDoc
    
    End Sub

  3. #3

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Print a form in centre alignment

    Hi MartinLiss,

    Thanks for your help and code.
    But in my case this alignment is not enough.
    Firstly your code prints the full picutre of the form including buttons, labels textboxes etc and From itself. But I want to print the data I type in the text boxes only.
    Secondly please assume that, my project is to print data on a cheque leaf.
    I tested your code both in Portrait and Landscape paper orientations. I want to print the data in Landscape paper orientation. In this orientation, your code prints in Left-Centre of a A4 paper (Landscape Mode). I want to print Top-Centre of a A4 paper.
    The best example for my project in another way is, How I can print address in a Letter Cover from VB Form ?.
    I hope you have got the idea that expect.

    With regards,
    Nasreen

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Re: Print a form in centre alignment

    Hi all,

    I am dveloping a small project to print Adresses on a Envelop using Laser Jet printers.

    Has anybody an idea how I can print a text content in a Form at the desired place of the envelop, (Normally to address at right-centre and from address at left bottom)

    With regards,
    Nasreen

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Print a form in centre alignment

    It might work better to use another bordless form and have your textbox data copied to labels on the other form and print the other form
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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