Hello,
I am getting the below error while migrating from VB6 to VB.Net:
Error 1 'PrintForm1' is not a member of 'System.Windows.Forms.Form'. in the below code:
Public Sub PrintScreen(ByRef frm As System.Windows.Forms.Form, ByRef FormHeight As Short)
'UPGRADE_ISSUE: PrintForm Component might require to be declared. frm.PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)
End Sub
The error is related to the 'System.Windows.Forms.Form' not containing the 'PrintForm1' as its member. In the project, I am sending different forms, with PrintForm Component, to a particular form using the above subroutine. According to the upgrade msg we have to declare the PrintForm1 Component in the subroutine. How can we change this code to get the desired effects?
Regards,
Simran Kaur.

Hello,
This is not a problem with PowerPacks as I am already referencing the PowerPack 3.0. There are no errors in the other forms with the PrintForm component. The form in which I am calling this sub doesn't has PrintForm1 component as it is only a parameter. How to declare this PrintForm1 component parameter in the sub?
Regards,
Simran Kaur.

PrintForm Component might require to be declared.

frm.PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)

The form "frm" must have a control that shoud be called PrintForm1.

To add a such control in the form "frm" you can:
1) On the designer of the form add the PrintForm Control
2) On the Load event, or any place in the form before calling the sub PrintScreen, and if there is no PrintForm control already defined,

Dim PrintForm1 as new PowerPacks.Printing.PrintForm
Me.Controls.Add(PrintForm1)

Hope this helps

Comments
was helpful

Hello,
I added Dim PrintForm1 As New PowerPacks.Printing.PrintForm
as a global variable in the module(not form) where PrintScreen sub is implemented.

If I add Me.Controls.Add(PrintForm1) in the PrintScreen sub, I am getting the below error.
Error 1 'Me' is not valid within a Module as the PrintScreen subroutine is in a module & not a form.

Instead if I add Me.Controls.Add(PrintForm1) in the calling form, I am getting the below error.
Error 2 Value of type 'Microsoft.VisualBasic.PowerPacks.Printing.PrintForm' cannot be converted to 'System.Windows.Forms.Control'.

And finally the error for frm.PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly) still persists
Error 3 'PrintForm1' is not a member of 'System.Windows.Forms.Form'.

Sorry.
Really you do not need to add the printform in the controls of the form.

Please try some thing like:

Public Sub PrintScreen(ByRef frm As System.Windows.Forms.Form, ByRef FormHeight As Short)
	PrintForm1.DocumentName = frm.name ' or fr.text or whatelse to identify it
	PrintForm1.Form = frm
	PrintForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPrinter
	PrintForm1.PrinterSettings = CType(resources.GetObject("PrintForm1.PrinterSettings"), System.Drawing.Printing.PrinterSettings)
	PrintForm1.PrintFileName = Nothing
.
.
	PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)
.
.

End Sub

or whatelse you need to do with the PrintForm1.

Hope this helps

Comments
was helpful

Hello,
Your code works perfectly.
Thanks for the solution.
Regards,
Simran.

This question has already been answered. Start a new discussion instead.