I have textbox, picture box . How I can print the form?
Printable View
I have textbox, picture box . How I can print the form?
vb 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 cmdPrintForm_Click() Dim lWidth As Long, 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, 0, 0, lWidth, lHeight Printer.EndDoc End Sub
How I can modify the code?
It print the whole in the form including the control box and command button.
Don't forms have a PrintForm method that you can use?
Sometimes printform does print controls like grids or picture boxes.
It does print the whole form. That is what I thought you asked for.
All you want to do is print the text within the textbox and the picture within the picture box?
Yes.Quote:
All you want to do is print the text within the textbox and the picture within the picture box?
How aboutCode:Printer.Print Text1.Text
Printer.Print Picture1.Picuture
Printer.EndDoc
Review the Printer object in the Object Browser to see all its functions and methods etc. You will see there are all kinds of thigs you can manipulate with it. To choose the printer it will be printed to you will need to add a commondialog control to your form and execute the .ShowPrinter method to present the user with a list of printers they can choose from. Then assign the selection to the Printer object relevant property.
You may have also wanted to choose a better thread title as you would have gotten more direct replies ;)
I use common dialog box. How I can execute the selected printer devices and assign the selected printer to print the paper?Quote:
Originally Posted by RobDog888
Commondialog1.ShowPrinter.
Then after the selections have been made you can read what was selected and assign to the Printer object correcponding properties.